From 5a0a20c226bfd7c2101dc5b5a7120a4813c4292f Mon Sep 17 00:00:00 2001 From: yqhan Date: Sat, 7 Jan 2023 14:53:01 +0800 Subject: [PATCH] Modify the worker test case module issue: https://gitee.com/openharmony/xts_acts/issues/I68FR8 Signed-off-by: yqhan --- .../worker_lib_standard/AppScope/app.json | 21 + .../resources/base/element/string.json | 8 + .../resources/base/media/app_icon.png} | Bin .../ets_utils/worker_lib_standard/BUILD.gn | 35 +- .../ets_utils/worker_lib_standard/Test.json | 12 +- .../src/main/ets/Application/AbilityStage.ts} | 45 +- .../src/main/ets/MainAbility/MainAbility.ts | 51 + .../src/main/ets/MainAbility/pages/index.ets} | 94 +- .../src/main/ets/TestAbility/TestAbility.ts | 49 + .../src/main/ets/TestAbility/pages/index.ets | 48 + .../ets/TestRunner/OpenHarmonyTestRunner.ts | 78 + .../src/main/ets/test/List.test.js} | 48 +- .../src/main/ets}/test/ThreadWorker.test.js | 209 +- .../src/main/ets/test/WorkerTest.test.js} | 2700 ++++++++--------- .../src/main/ets}/workers/newworker.js | 0 .../src/main/ets}/workers/newworker_002.js | 0 .../src/main/ets}/workers/newworker_003.js | 0 .../src/main/ets}/workers/newworker_004.js | 0 .../src/main/ets}/workers/newworker_005.js | 0 .../src/main/ets}/workers/newworker_006.js | 0 .../src/main/ets}/workers/newworker_007.js | 0 .../src/main/ets}/workers/newworker_008.js | 0 .../src/main/ets}/workers/newworker_009.js | 2 +- .../src/main/ets}/workers/newworker_0091.js | 0 .../src/main/ets}/workers/newworker_010.js | 2 +- .../src/main/ets}/workers/newworker_0101.js | 0 .../src/main/ets}/workers/newworker_011.js | 2 +- .../src/main/ets}/workers/newworker_0111.js | 0 .../src/main/ets}/workers/newworker_012.js | 2 +- .../src/main/ets}/workers/newworker_0121.js | 2 +- .../src/main/ets}/workers/newworker_0122.js | 0 .../src/main/ets}/workers/newworker_013.js | 2 +- .../src/main/ets}/workers/newworker_0131.js | 0 .../src/main/ets}/workers/newworker_014.js | 2 +- .../src/main/ets}/workers/newworker_0141.js | 0 .../src/main/ets}/workers/newworker_015.js | 2 +- .../src/main/ets}/workers/newworker_0151.js | 2 +- .../src/main/ets}/workers/newworker_0152.js | 0 .../src/main/ets}/workers/worker.js | 108 +- .../src/main/ets}/workers/worker_002.js | 44 +- .../src/main/ets}/workers/worker_003.js | 42 +- .../src/main/ets}/workers/worker_004.js | 44 +- .../src/main/ets}/workers/worker_005.js | 40 +- .../src/main/ets}/workers/worker_006.js | 40 +- .../src/main/ets}/workers/worker_007.js | 40 +- .../src/main/ets}/workers/worker_008.js | 44 +- .../src/main/ets}/workers/worker_009.js | 88 +- .../src/main/ets}/workers/worker_0091.js | 40 +- .../src/main/ets}/workers/worker_010.js | 98 +- .../src/main/ets}/workers/worker_0101.js | 42 +- .../src/main/ets}/workers/worker_011.js | 98 +- .../src/main/ets}/workers/worker_0111.js | 42 +- .../src/main/ets}/workers/worker_012.js | 98 +- .../src/main/ets}/workers/worker_0121.js | 70 +- .../src/main/ets}/workers/worker_0122.js | 48 +- .../src/main/ets}/workers/worker_013.js | 98 +- .../src/main/ets}/workers/worker_0131.js | 42 +- .../src/main/ets}/workers/worker_014.js | 98 +- .../src/main/ets}/workers/worker_0141.js | 44 +- .../src/main/ets}/workers/worker_015.js | 90 +- .../src/main/ets}/workers/worker_0151.js | 88 +- .../src/main/ets}/workers/worker_0152.js | 42 +- .../entry/src/main/module.json | 40 + .../main/resources/base/element/color.json | 8 + .../main/resources/base/element/string.json | 24 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/main_pages.json | 5 + .../signature/openharmony_sx.p7b | Bin 3434 -> 3436 bytes .../worker_lib_standard/src/main/config.json | 96 - .../src/main/js/MainAbility/app.js | 23 - .../src/main/js/MainAbility/i18n/en-US.json | 11 - .../src/main/js/MainAbility/i18n/zh-CN.json | 11 - .../main/js/MainAbility/pages/index/index.css | 39 - .../main/js/MainAbility/pages/index/index.hml | 21 - .../src/main/js/TestAbility/i18n/en-US.json | 8 - .../src/main/js/TestAbility/i18n/zh-CN.json | 8 - .../main/js/TestAbility/pages/index/index.css | 50 - .../main/js/TestAbility/pages/index/index.hml | 21 - .../js/TestRunner/OpenHarmonyTestRunner.js | 59 - .../src/main/js/test/List.test.js | 21 - .../main/resources/base/element/string.json | 28 - 81 files changed, 2678 insertions(+), 2739 deletions(-) create mode 100644 commonlibrary/ets_utils/worker_lib_standard/AppScope/app.json create mode 100644 commonlibrary/ets_utils/worker_lib_standard/AppScope/resources/base/element/string.json rename commonlibrary/ets_utils/worker_lib_standard/{src/main/resources/base/media/icon.png => AppScope/resources/base/media/app_icon.png} (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/TestAbility/app.js => entry/src/main/ets/Application/AbilityStage.ts} (75%) create mode 100644 commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/MainAbility/MainAbility.ts rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility/pages/index/index.js => entry/src/main/ets/MainAbility/pages/index.ets} (52%) create mode 100644 commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/TestAbility/TestAbility.ts create mode 100644 commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/TestAbility/pages/index.ets create mode 100644 commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/TestAbility/pages/index/index.js => entry/src/main/ets/test/List.test.js} (78%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js => entry/src/main/ets}/test/ThreadWorker.test.js (87%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/test/Worker.test.js => entry/src/main/ets/test/WorkerTest.test.js} (84%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_002.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_003.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_004.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_005.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_006.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_007.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_008.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_009.js (93%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_0091.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_010.js (94%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_0101.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_011.js (94%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_0111.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_012.js (94%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_0121.js (92%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_0122.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_013.js (94%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_0131.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_014.js (94%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_0141.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_015.js (94%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_0151.js (94%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/newworker_0152.js (100%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_002.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_003.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_004.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_005.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_006.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_007.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_008.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_009.js (88%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_0091.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_010.js (92%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_0101.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_011.js (92%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_0111.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_012.js (92%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_0121.js (91%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_0122.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_013.js (92%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_0131.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_014.js (92%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_0141.js (97%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_015.js (92%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_0151.js (92%) rename commonlibrary/ets_utils/worker_lib_standard/{src/main/js/MainAbility => entry/src/main/ets}/workers/worker_0152.js (97%) create mode 100644 commonlibrary/ets_utils/worker_lib_standard/entry/src/main/module.json create mode 100644 commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/element/color.json create mode 100644 commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/element/string.json create mode 100644 commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/media/icon.png create mode 100644 commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/profile/main_pages.json delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/config.json delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/app.js delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/i18n/en-US.json delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/i18n/zh-CN.json delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/pages/index/index.css delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/pages/index/index.hml delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/i18n/en-US.json delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/i18n/zh-CN.json delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.css delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.hml delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestRunner/OpenHarmonyTestRunner.js delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/js/test/List.test.js delete mode 100644 commonlibrary/ets_utils/worker_lib_standard/src/main/resources/base/element/string.json diff --git a/commonlibrary/ets_utils/worker_lib_standard/AppScope/app.json b/commonlibrary/ets_utils/worker_lib_standard/AppScope/app.json new file mode 100644 index 000000000..4f3958663 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "com.example.workertest", + "vendor": "huawei", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "debug": false, + "description": "$string:app_name", + "keepAlive": true, + "singleUser": true, + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/commonlibrary/ets_utils/worker_lib_standard/AppScope/resources/base/element/string.json b/commonlibrary/ets_utils/worker_lib_standard/AppScope/resources/base/element/string.json new file mode 100644 index 000000000..829a11057 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"app_name", + "value":"WorkerTest" + } + ] +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/resources/base/media/icon.png b/commonlibrary/ets_utils/worker_lib_standard/AppScope/resources/base/media/app_icon.png similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/resources/base/media/icon.png rename to commonlibrary/ets_utils/worker_lib_standard/AppScope/resources/base/media/app_icon.png diff --git a/commonlibrary/ets_utils/worker_lib_standard/BUILD.gn b/commonlibrary/ets_utils/worker_lib_standard/BUILD.gn index b3fd8e99f..feafa60ab 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/BUILD.gn +++ b/commonlibrary/ets_utils/worker_lib_standard/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# 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 @@ -14,23 +14,30 @@ import("//test/xts/tools/build/suite.gni") ohos_js_hap_suite("worker_js_hap") { - hap_profile = "./src/main/config.json" + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" deps = [ - ":worker_js_assets", - ":worker_resources", + ":workertest_js_assets", + ":workertest_resources", ] - certificate_profile = "./signature/openharmony_sx.p7b" - hap_name = "ActsWorkerJSTest" - + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsWorkerJsTest" subsystem_name = "commonlibrary" part_name = "ets_utils" } -ohos_js_assets("worker_js_assets") { - js2abc = true - hap_profile = "./src/main/config.json" - source_dir = "./src/main/js" + +ohos_app_scope("workertest_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] } -ohos_resources("worker_resources") { - sources = [ "./src/main/resources" ] - hap_profile = "./src/main/config.json" + +ohos_js_assets("workertest_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("workertest_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":workertest_app_profile" ] + hap_profile = "entry/src/main/module.json" } diff --git a/commonlibrary/ets_utils/worker_lib_standard/Test.json b/commonlibrary/ets_utils/worker_lib_standard/Test.json index 4a8621156..4c3027d4f 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/Test.json +++ b/commonlibrary/ets_utils/worker_lib_standard/Test.json @@ -1,19 +1,19 @@ { - "description": "Configuration for startup worker js api Tests", + "description": "Configuration for hjunit demo Tests", "driver": { "type": "OHJSUnitTest", "test-timeout": "800000", - "bundle-name": "com.example.workerxts", - "package-name": "com.example.workerxts", + "bundle-name": "com.example.workertest", + "module-name": "entry", "shell-timeout": "800000" }, "kits": [ { "test-file-name": [ - "ActsWorkerJSTest.hap" + "ActsWorkerJsTest.hap" ], "type": "AppInstallKit", "cleanup-apps": true } - ] -} \ No newline at end of file + ] +} diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/app.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/Application/AbilityStage.ts similarity index 75% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/app.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/Application/AbilityStage.ts index cbdada4ad..dc5a43d9b 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/app.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/Application/AbilityStage.ts @@ -1,23 +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. - */ -export default { - onCreate() { - console.info('TestApplication onCreate') - - }, - onDestroy() { - console.info("TestApplication onDestroy"); - } -}; +/* + * 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.app.ability.AbilityStage" + +var printLog0 = 'Worker:AbilityStage:' +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.info(printLog0 + "onCreate") + } +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/MainAbility/MainAbility.ts b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 000000000..f17764a71 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/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.app.ability.UIAbility'; + +var printLog = 'Worker:MainAbility:' +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.info(printLog + 'onCreate') + } + + onDestroy() { + console.info(printLog + 'onDestroy') + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.info(printLog + 'onWindowStageCreate') + + windowStage.loadContent("MainAbility/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)) + }); + } + + onWindowStageDestroy() { + console.info(printLog + 'onWindowStageDestroy') + } + + onForeground() { + console.info(printLog + 'onForeground') + } + + onBackground() { + console.info(printLog + 'onBackground') + } +}; diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/pages/index/index.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/MainAbility/pages/index.ets similarity index 52% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/pages/index/index.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/MainAbility/pages/index.ets index fbba13973..f0c389008 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/pages/index/index.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/MainAbility/pages/index.ets @@ -1,48 +1,46 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import app from '@system.app' -import device from '@system.device' -import router from '@system.router' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import { Hypium } from '@ohos/hypium' -import testsuite from '../../../test/List.test' - - -export default { - data: { - title: '' - }, - onInit() { - this.title = this.$t('strings.world'); - }, - onShow() { - console.info('onShow finish') - var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - console.info('start run testcase!!!') - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - }, - touchMove(e) { - if (e.direction === 'right') { - this.appExit(); - } - }, - appExit() { - app.terminate() - } -} - - +/* + * 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'; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../../test/List.test' + +@Entry +@Component +struct Index { + @State message: string = 'MainAbility Worker' + + aboutToAppear() { + console.info("start run testcase!!!!") + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/TestAbility/TestAbility.ts b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 000000000..36c9cf978 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,49 @@ +/* + * 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.app.ability.UIAbility' + +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)) + }); + + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/TestAbility/pages/index.ets b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 000000000..b93567f96 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/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/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..c914d3e1d --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/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.workertest.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/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/List.test.js similarity index 78% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/List.test.js index 88b083a7f..f971dc25f 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/List.test.js @@ -1,26 +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. - */ - -export default { - data: { - title: "" - }, - onInit() { - this.title = this.$t('strings.world'); - } -} - - - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import WorkerTest from './WorkerTest.test.js' +import threadWorkerTest from './ThreadWorker.test.js' + +export default function List() { + WorkerTest() + threadWorkerTest() +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/test/ThreadWorker.test.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js similarity index 87% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/test/ThreadWorker.test.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js index 49c0a7660..c279056cb 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/test/ThreadWorker.test.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js @@ -26,7 +26,7 @@ describe('threadWorkerTest', function () { function promiseCase() { let p = new Promise(function (resolve, reject) { setTimeout(function () { - resolve() + resolve(0) }, 100) }).then(undefined, (error) => { }) @@ -39,7 +39,7 @@ describe('threadWorkerTest', function () { * @tc.desc: worker constructor to Creates a worker instance. */ it('threadWorker_constructor_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let isTerminate = false ss.onexit = function () { @@ -60,7 +60,7 @@ describe('threadWorkerTest', function () { * @tc.desc: worker constructor to Creates a worker instance. */ it('threadWorker_constructor_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js", {name:"new worker", shared:"False"}) + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js", {name:"1st worker", shared: false}) let isTerminate = false ss.onexit = function () { @@ -81,7 +81,8 @@ describe('threadWorkerTest', function () { * @tc.desc: worker constructor to Creates a worker instance. */ it('threadWorker_constructor_test_003', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js", {type:"classic", name:"new worker", shared:"false"}) + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js", + {type:"classic", name:"2st worker", shared: false}) let isTerminate = false ss.onexit = function () { @@ -102,7 +103,8 @@ describe('threadWorkerTest', function () { * @tc.desc: worker constructor to Creates a worker instance. */ it('threadWorker_constructor_test_004', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js", {type:"classic", name:"new worker", shared:"true"}) + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js", + {type:"classic", name:"3st worker", shared: true}) let isTerminate = false ss.onexit = function () { @@ -127,7 +129,7 @@ describe('threadWorkerTest', function () { try { let a = 0 while (a <= 8) { - ss[a] = new worker.ThreadWorker("workers/newworker.js") + ss[a] = new worker.ThreadWorker("entry/ets/workers/newworker.js") a += 1 } } catch (error) { @@ -156,7 +158,7 @@ describe('threadWorkerTest', function () { */ it('threadWorker_constructor_test_006', 0, async function (done) { try { - let ss = new worker.ThreadWorker("workers/newworker.js", {type:"other", name:"new worker", shared:"true"}) + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js", {type:"other", name:"worker"}) } catch (error) { expect(error.name == "BusinessError").assertTrue() expect(error.message == "the type must be classic, unsupport others now.").assertTrue() @@ -170,7 +172,8 @@ describe('threadWorkerTest', function () { */ it('threadWorker_constructor_test_007', 0, async function (done) { try { - let ss = new worker.ThreadWorker("workers/newworker.js", {type:1, name:"new worker", shared:"true"}) + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js", + {type:1, name:"new worker", shared: true}) } catch (error) { expect(error.name == "BusinessError").assertTrue() expect(error.message == "the type of type must be string.").assertTrue() @@ -184,7 +187,7 @@ describe('threadWorkerTest', function () { */ it('threadWorker_constructor_test_008', 0, async function (done) { try { - let ss = new worker.ThreadWorker("workers/newworker.js", {type:"classic1", name:1, shared:"true"}) + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js", {type:"classic", name:1, shared: true}) } catch (error) { expect(error.name == "BusinessError").assertTrue() expect(error.message == "the type of name in worker must be string.").assertTrue() @@ -213,7 +216,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Sends a message to the worker thread. */ it('threadWorker_postMessage_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_002.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_002.js") let res = undefined let flag = false @@ -248,7 +251,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Sends a message to the worker thread. */ it('threadWorker_postMessage_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_003.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_003.js") let res = undefined let flag = false @@ -283,7 +286,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Sends a message to the worker thread. */ it('threadWorker_postMessage_test_003', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_004.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_004.js") let res = undefined let flag = false @@ -317,7 +320,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Sends a message to the worker thread. */ it('threadWorker_postMessage_test_004', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_005.js", {name: "zhangsan"}) + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_005.js", {name: "zhangsan"}) let res = undefined let flag = false @@ -353,7 +356,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Sends a message to the worker thread. */ it('threadWorker_postMessage_test_005', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_006.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_006.js") let isTerminate = false ss.onexit = function () { @@ -393,7 +396,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Sends a message to the worker thread. */ it('threadWorker_postMessage_test_006', 0, async function (done) { - const ss = new worker.ThreadWorker("workers/newworker_007.js") + const ss = new worker.ThreadWorker("entry/ets/workers/newworker_007.js") let res = undefined let flag = false @@ -427,7 +430,7 @@ describe('threadWorkerTest', function () { */ it('threadWorker_postMessage_test_007', 0, async function (done) { try { - const ss = new worker.ThreadWorker("workers/newworker_007.js") + const ss = new worker.ThreadWorker("entry/ets/workers/newworker_007.js") ss.postMessage() } catch (error) { expect(error.name).assertEqual("BusinessError") @@ -442,7 +445,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Terminates the worker thread to stop the worker from receiving messages. */ it('threadWorker_terminate_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let res = 0 let flag = false @@ -466,7 +469,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Terminates the worker thread to stop the worker from receiving messages. */ it('threadWorker_terminate_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let res = 0 let flag = false @@ -493,7 +496,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Terminates the worker thread to stop the worker from receiving messages. */ it('threadWorker_terminate_test_003', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let res = 0 let flag = false @@ -528,7 +531,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Adds an event listener to the worker. */ it('threadWorker_on_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -540,7 +543,7 @@ describe('threadWorkerTest', function () { times++ }) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -557,7 +560,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Adds an event listener to the worker. */ it('threadWorker_on_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -572,8 +575,8 @@ describe('threadWorkerTest', function () { times++ }) - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "lisi"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -590,7 +593,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Adds an event listener to the worker. */ it('threadWorker_on_test_003', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -604,7 +607,7 @@ describe('threadWorkerTest', function () { for (let i=0;i<10;i++) { - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) } ss.terminate() @@ -623,7 +626,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Adds an event listener to the worker when throw error. */ it('threadWorker_on_test_004', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let isTerminate = false try { @@ -648,7 +651,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Adds an event listener to the worker when throw error. */ it('threadWorker_on_test_005', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let isTerminate = false try { @@ -673,7 +676,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Adds an event listener to the worker when throw error. */ it('threadWorker_on_test_006', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let isTerminate = false try { @@ -698,15 +701,16 @@ describe('threadWorkerTest', function () { after it is invoked once when throw error. */ it('threadWorker_on_test_007', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let isTerminate = false + let times = 0 try { ss.on("zhangsan", ()=>{ times++ }) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.onexit = function () { isTerminate = true } @@ -732,7 +736,7 @@ describe('threadWorkerTest', function () { after it is invoked once. */ it('threadWorker_once_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -743,7 +747,7 @@ describe('threadWorkerTest', function () { ss.once("zhangsan", ()=>{ times++ }) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -761,7 +765,7 @@ describe('threadWorkerTest', function () { after it is invoked once. */ it('threadWorker_once_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -775,7 +779,7 @@ describe('threadWorkerTest', function () { for (let i=0;i<10;i++) { - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) } ss.terminate() @@ -793,7 +797,7 @@ describe('threadWorkerTest', function () { after it is invoked once. */ it('threadWorker_once_test_003', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -809,8 +813,8 @@ describe('threadWorkerTest', function () { times++ }) - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "lisi"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -827,7 +831,7 @@ describe('threadWorkerTest', function () { after it is invoked once when throw error. */ it('threadWorker_once_test_004', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -856,7 +860,7 @@ describe('threadWorkerTest', function () { after it is invoked once when throw error. */ it('threadWorker_once_test_005', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let isTerminate = false @@ -882,7 +886,7 @@ describe('threadWorkerTest', function () { after it is invoked once when throw error. */ it('threadWorker_once_test_006', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let isTerminate = false @@ -908,15 +912,16 @@ describe('threadWorkerTest', function () { after it is invoked once when throw error. */ it('threadWorker_once_test_007', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let isTerminate = false + let times = 0 try { ss.once("zhangsan", ()=>{ times++ }) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.onexit = function () { isTerminate = true } @@ -941,7 +946,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Add an event listener to the Worker. */ it('threadWorker_addEventListener_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -953,8 +958,8 @@ describe('threadWorkerTest', function () { times++ }) - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -971,7 +976,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Add an event listener to the Worker. */ it('threadWorker_addEventListener_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -986,8 +991,8 @@ describe('threadWorkerTest', function () { times++ }) - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "lisi"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -1004,7 +1009,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Add an event listener to the Worker. */ it('threadWorker_addEventListener_test_003', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -1018,7 +1023,7 @@ describe('threadWorkerTest', function () { for (let i=0;i<10;i++) { - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) } ss.terminate() @@ -1036,7 +1041,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Add an event listener to the Worker when throw error. */ it('threadWorker_addEventListener_test_004', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -1065,7 +1070,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Add an event listener to the Worker when throw error. */ it('threadWorker_addEventListener_test_005', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -1092,7 +1097,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Add an event listener to the Worker when throw error. */ it('threadWorker_addEventListener_test_006', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -1119,7 +1124,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Add an event listener to the Worker when throw error. */ it('threadWorker_addEventListener_test_007', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -1129,7 +1134,7 @@ describe('threadWorkerTest', function () { times++ }) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.onexit = function () { isTerminate = true @@ -1156,7 +1161,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Add an event listener to the Worker when throw error. */ it('threadWorker_addEventListener_test_008', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let times = 0 let isTerminate = false @@ -1166,7 +1171,7 @@ describe('threadWorkerTest', function () { times++ }) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.onexit = function () { isTerminate = true @@ -1175,7 +1180,7 @@ describe('threadWorkerTest', function () { while (!isTerminate) { await promiseCase() } - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) } catch (error) { expect(error.name).assertEqual("BusinessError") expect(error.message).assertEqual("Worker instance is not running, maybe worker has been terminated") @@ -1189,7 +1194,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event listener to the worker. */ it('threadWorker_off_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1201,13 +1206,13 @@ describe('threadWorkerTest', function () { zhangSanTimes++ }) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) expect(zhangSanTimes).assertEqual(1) ss.off("zhangsan") - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -1224,7 +1229,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event listener to the worker. */ it('threadWorker_off_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1236,8 +1241,8 @@ describe('threadWorkerTest', function () { zhangSanTimes++ }) - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) expect(zhangSanTimes).assertEqual(2) for (let i=0;i<3;i++) @@ -1245,7 +1250,7 @@ describe('threadWorkerTest', function () { ss.off("zhangsan") } - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -1262,7 +1267,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event listener to the worker when throw error. */ it('threadWorker_off_test_003', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1293,7 +1298,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event listener to the worker when throw error. */ it('threadWorker_off_test_004', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1323,7 +1328,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event listener to the worker when throw error. */ it('threadWorker_off_test_005', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1353,7 +1358,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event defined for the worker. */ it('threadWorker_removeListener_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1365,13 +1370,13 @@ describe('threadWorkerTest', function () { zhangSanTimes++ }) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) expect(zhangSanTimes).assertEqual(1) ss.removeEventListener("zhangsan") - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -1388,7 +1393,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event defined for the worker. */ it('threadWorker_removeListener_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1400,8 +1405,8 @@ describe('threadWorkerTest', function () { zhangSanTimes++ }) - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) expect(zhangSanTimes).assertEqual(2) for (let i=0;i<3;i++) @@ -1409,7 +1414,7 @@ describe('threadWorkerTest', function () { ss.removeEventListener("zhangsan") } - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -1426,7 +1431,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event defined for the worker. */ it('threadWorker_removeListener_test_003', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1443,21 +1448,21 @@ describe('threadWorkerTest', function () { liSiTimes++ }) - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) expect(zhangSanTimes).assertEqual(2) - ss.dispatchEvent({type: "lisi"}) - ss.dispatchEvent({type: "lisi"}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) expect(liSiTimes).assertEqual(2) ss.removeAllListener() - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) expect(zhangSanTimes).assertEqual(2) - ss.dispatchEvent({type: "lisi"}) - ss.dispatchEvent({type: "lisi"}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) ss.terminate() while (!isTerminate) { @@ -1474,7 +1479,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event defined for the worker when throw error. */ it('threadWorker_removeListener_test_003', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1504,7 +1509,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event defined for the worker when throw error. */ it('threadWorker_removeListener_test_004', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1534,7 +1539,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event defined for the worker when throw error. */ it('threadWorker_removeListener_test_005', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1564,7 +1569,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Removes an event defined for the worker when throw error. */ it('threadWorker_removeListener_test_006', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker.js") let zhangSanTimes = 0 let isTerminate = false @@ -1594,7 +1599,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Close the worker thread to stop the worker from receiving messages. */ it('threadWorker_parentPortClose_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_008.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_008.js") let res = 0 let flag = false @@ -1618,7 +1623,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Close the worker thread to stop the worker from receiving messages. */ it('threadWorker_parentPortClose_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_008.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_008.js") let res = 0 let flag = false @@ -1654,7 +1659,7 @@ describe('threadWorkerTest', function () { a message that cannot be serialized. The event handler is executed in the host thread */ it('threadWorker_onmessageerror_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_008.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_008.js") let res = 0 let flag = false @@ -1681,7 +1686,7 @@ describe('threadWorkerTest', function () { a message that cannot be serialized. The event handler is executed in the host thread */ it('threadWorker_onmessageerror_test_002', 0, async function (done) { - var ss = new worker.ThreadWorker("workers/newworker_008.js") + var ss = new worker.ThreadWorker("entry/ets/workers/newworker_008.js") var res = 0 var flag = false @@ -1709,7 +1714,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Create a second worker. */ it('threadWorker_new_second_worker_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_009.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_009.js") let flag = false let res = undefined let isTerminate = false @@ -1752,7 +1757,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Create a third worker. */ it('threadWorker_new_second_worker_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_012.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_012.js") let flag = false let res = undefined let isTerminate = false @@ -1796,7 +1801,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Check if the postMessage function of the second worker is ok. */ it('threadWorker_second_worker_postMessage_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_010.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_010.js") let flag = false let res = undefined let isTerminate = false @@ -1840,7 +1845,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Check if the postMessage function of the second worker is ok. */ it('threadWorker_second_worker_postMessage_test_002', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_013.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_013.js") let flag = false let res = undefined let isTerminate = false @@ -1884,7 +1889,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Check if the postMessage function of the second worker is ok. */ it('threadWorker_second_worker_postMessage_test_003', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_014.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_014.js") let flag = false let res = undefined let isTerminate = false @@ -1929,7 +1934,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Check if the postMessage function of the third worker is ok. */ it('threadWorker_third_worker_postMessage_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_015.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_015.js") let flag = false let res = undefined let isTerminate = false @@ -1966,7 +1971,7 @@ describe('threadWorkerTest', function () { * @tc.desc: Check if the terminate function of the second worker is ok. */ it('threadWorker_second_worker_terminate_test_001', 0, async function (done) { - let ss = new worker.ThreadWorker("workers/newworker_011.js") + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_011.js") let flag = false let res = undefined let isTerminate = false diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/test/Worker.test.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js similarity index 84% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/test/Worker.test.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js index 20bc6569a..c74e0a7ca 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/test/Worker.test.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js @@ -1,1352 +1,1350 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License') - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import app from '@system.app' -import worker from "@ohos.worker" -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -export default function workerTest() { -describe('workerTest', function () { - - afterAll(function () { - console.info('total case over') - }) - - function promiseCase() { - let p = new Promise(function (resolve, reject) { - setTimeout(function () { - resolve() - }, 100) - }).then(undefined, (error) => { - }) - return p - } - - // check worker constructor is ok - /** - * @tc.name: worker_constructor_test_001 - * @tc.desc: worker constructor to Creates a worker instance. - * @tc.author: hanyuqing - */ - it('worker_constructor_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - - expect(ss != null).assertTrue() - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - done() - }) - - /** - * @tc.name: worker_constructor_test_002 - * @tc.desc: worker constructor to Creates a worker instance. - * @tc.author: hanyuqing - */ - it('worker_constructor_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js", {name:"second worker", shared:"False"}) - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - - expect(ss != null).assertTrue() - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - done() - }) - - /** - * @tc.name: worker_constructor_test_003 - * @tc.desc: worker constructor to Creates a worker instance. - * @tc.author: hanyuqing - */ - it('worker_constructor_test_003', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js", {type:"classic", name:"second worker", shared:"false"}) - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - - expect(ss != null).assertTrue() - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - done() - }) - - /** - * @tc.name: worker_constructor_test_004 - * @tc.desc: worker constructor to Creates a worker instance. - * @tc.author: hanyuqing - */ - it('worker_constructor_test_004', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js", {type:"classic", name:"third worker", shared:"true"}) - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - - expect(ss != null).assertTrue() - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - done() - }) - - // check postMessage is ok - // main post "hello world", will receive "hello world worker" - /** - * @tc.name: worker_postMessage_test_001 - * @tc.desc: Sends a message to the worker thread. - * @tc.author: hanyuqing - */ - it('worker_postMessage_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker_002.js") - - let res = undefined - let flag = false - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.onmessage = function (e) { - res = e.data - flag = true - } - - ss.postMessage("hello world") - while (!flag) { - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(res).assertEqual("hello world worker") - done() - }) - - // check postMessage is ok - // main post 12 , will receive 12 * 2 + 1 - /** - * @tc.name: worker_postMessage_test_002 - * @tc.desc: Sends a message to the worker thread. - * @tc.author: hanyuqing - */ - it('worker_postMessage_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker_003.js") - - let res = undefined - let flag = false - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.onmessage = function (e) { - res = e.data - flag = true - } - - ss.postMessage(12) - while (!flag) { - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(res).assertEqual(25) - done() - }) - - // check postMessage is ok - // main post {message:"hello world"} , will receive {message:"hello world worker"} - /** - * @tc.name: worker_postMessage_test_003 - * @tc.desc: Sends a message to the worker thread. - * @tc.author: hanyuqing - */ - it('worker_postMessage_test_003', 0, async function (done) { - let ss = new worker.Worker("workers/worker_004.js") - - let res = undefined - let flag = false - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.onmessage = function (e) { - res = e.data.message - flag = true - } - - ss.postMessage({"message":"hello world"}) - while (!flag) { - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(res).assertEqual("hello world worker") - done() - }) - - // check worker name is ok - /** - * @tc.name: worker_postMessage_test_004 - * @tc.desc: Sends a message to the worker thread. - * @tc.author: hanyuqing - */ - it('worker_postMessage_test_004', 0, async function (done) { - let ss = new worker.Worker("workers/worker_005.js", {name: "zhangsan"}) - - let res = undefined - let flag = false - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.onmessage = function (e) { - res = e.data - console.info("worker:: type " + e.type) - console.info("worker:: timeStamp " + e.timeStamp) - flag = true - } - - ss.postMessage("hello world") - while (!flag) { - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(res).assertEqual("zhangsan") - done() - }) - - // check worker transfer buffer is ok - /** - * @tc.name: worker_postMessage_test_005 - * @tc.desc: Sends a message to the worker thread. - * @tc.author: hanyuqing - */ - it('worker_postMessage_test_005', 0, async function (done) { - let ss = new worker.Worker("workers/worker_006.js") - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - - const buffer = new ArrayBuffer(8) - expect(buffer.byteLength).assertEqual(8) - ss.postMessage(buffer, [buffer]) - let length = undefined - let exception = undefined - try { - length = buffer.byteLength - } catch (e) { - exception = e.message - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - console.log("worker:: length is " + length) - console.log("worker:: exception is " + exception) - - if (typeof exception == "undefined") { - expect(length).assertEqual(0) - } else { - expect(exception).assertEqual("IsDetachedBuffer") - } - done() - }) - - // check worker handle error is ok - /** - * @tc.name: worker_postMessage_test_006 - * @tc.desc: Sends a message to the worker thread. - * @tc.author: hanyuqing - */ - it('worker_postMessage_test_006', 0, async function (done) { - let ss = new worker.Worker("workers/worker_007.js") - - let res = undefined - let flag = false - let isTerminate = false - - ss.onerror = function (e) { - res = e.message - console.info("worker:: filename " + e.filename) - console.info("worker:: lineno " + e.lineno) - console.info("worker:: colno " + e.colno) - console.info("worker:: error " + e.error) - flag = true - } - ss.onexit = function () { - isTerminate = true - } - - ss.postMessage("hello world") - while (!flag) { - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(res).assertEqual("Error: 123") - done() - }) - - // check worker terminate is ok - /** - * @tc.name: worker_terminate_test_001 - * @tc.desc: Terminates the worker thread to stop the worker from receiving messages. - * @tc.author: hanyuqing - */ - it('worker_terminate_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - let res = 0 - let flag = false - - ss.onexit = function () { - flag = true - res++ - } - - ss.terminate() - while (!flag) { - await promiseCase() - } - - expect(res).assertEqual(1) - done() - }) - - // check worker terminate is ok - /** - * @tc.name: worker_terminate_test_002 - * @tc.desc: Terminates the worker thread to stop the worker from receiving messages. - * @tc.author: hanyuqing - */ - it('worker_terminate_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - let res = 0 - let flag = false - - ss.onexit = function () { - flag = true - res++ - } - - // Repeated execution terminate - ss.terminate() - ss.terminate() - - while (!flag) { - await promiseCase() - } - - expect(res).assertEqual(1) - done() - }) - - // check worker terminate is ok - /** - * @tc.name: worker_terminate_test_003 - * @tc.desc: Terminates the worker thread to stop the worker from receiving messages. - * @tc.author: hanyuqing - */ - it('worker_terminate_test_003', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - let res = 0 - let flag = false - - ss.onexit = function () { - flag = true - res++ - } - ss.onmessage = function (e) { - res++ - } - - ss.terminate() - while (!flag) { - await promiseCase() - } - expect(res).assertEqual(1) - - ss.postMessage("hello world") - await promiseCase() - expect(res).assertEqual(1) - done() - }) - - // check worker on function is ok - /** - * @tc.name: worker_on_test_001 - * @tc.desc: Adds an event listener to the worker. - * @tc.author: hanyuqing - */ - it('worker_on_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let times = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.on("zhangsan", ()=>{ - times++ - }) - - ss.dispatchEvent({type: "zhangsan"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(times).assertEqual(1) - done() - }) - - // check worker on function is ok - /** - * @tc.name: worker_on_test_002 - * @tc.desc: Adds an event listener to the worker. - * @tc.author: hanyuqing - */ - it('worker_on_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let times = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.on("zhangsan", ()=>{ - times-- - }) - ss.on("lisi", ()=>{ - times++ - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "lisi"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(times).assertEqual(0) - done() - }) - - // check worker on function is ok - /** - * @tc.name: worker_on_test_003 - * @tc.desc: Adds an event listener to the worker. - * @tc.author: hanyuqing - */ - it('worker_on_test_003', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let times = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.on("zhangsan", ()=>{ - times++ - }) - - for (let i=0;i<10;i++) - { - ss.dispatchEvent({type: "zhangsan"}) - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - console.log("times " + times) - expect(times).assertEqual(10) - done() - }) - - // check worker once function is ok - /** - * @tc.name: worker_once_test_001 - * @tc.desc: Adds an event listener to the worker and removes the event listener automically - after it is invoked once. - * @tc.author: hanyuqing - */ - it('worker_once_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let times = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.once("zhangsan", ()=>{ - times++ - }) - ss.dispatchEvent({type: "zhangsan"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(times).assertEqual(1) - done() - }) - - // check worker once function is ok - /** - * @tc.name: worker_once_test_002 - * @tc.desc: Adds an event listener to the worker and removes the event listener automically - after it is invoked once. - * @tc.author: hanyuqing - */ - it('worker_once_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let times = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.once("zhangsan", ()=>{ - times++ - }) - - for (let i=0;i<10;i++) - { - ss.dispatchEvent({type: "zhangsan"}) - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(times).assertEqual(1) - done() - }) - - /** - * @tc.name: worker_once_test_003 - * @tc.desc: Adds an event listener to the worker and removes the event listener automically - after it is invoked once. - * @tc.author: hanyuqing - */ - it('worker_once_test_003', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let times = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.once("zhangsan", ()=>{ - times-- - }) - - ss.once("lisi", ()=>{ - times++ - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "lisi"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(times).assertEqual(0) - done() - }) - - // check worker addEventListener function is ok - /** - * @tc.name: worker_addEventListener_test_001 - * @tc.desc: Add an event listener to the Worker. - * @tc.author: hanyuqing - */ - it('worker_addEventListener_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let times = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.addEventListener("zhangsan", ()=>{ - times++ - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(times).assertEqual(2) - done() - }) - - // check worker addEventListener function is ok - /** - * @tc.name: worker_addEventListener_test_002 - * @tc.desc: Add an event listener to the Worker. - * @tc.author: hanyuqing - */ - it('worker_addEventListener_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let times = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.addEventListener("zhangsan", ()=>{ - times++ - }) - ss.addEventListener("lisi", ()=>{ - times++ - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "lisi"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(times).assertEqual(2) - done() - }) - - // check worker addEventListener function is ok - /** - * @tc.name: worker_addEventListener_test_003 - * @tc.desc: Add an event listener to the Worker. - * @tc.author: hanyuqing - */ - it('worker_addEventListener_test_003', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let times = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.addEventListener("zhangsan", ()=>{ - times++ - }) - - for (let i=0;i<10;i++) - { - ss.dispatchEvent({type: "zhangsan"}) - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(times).assertEqual(10) - done() - }) - - // check worker off function is ok - /** - * @tc.name: worker_off_test_001 - * @tc.desc: Removes an event listener to the worker. - * @tc.author: hanyuqing - */ - it('worker_off_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let zhangSanTimes = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.on("zhangsan", ()=>{ - zhangSanTimes++ - }) - - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangSanTimes).assertEqual(1) - - ss.off("zhangsan") - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(zhangSanTimes).assertEqual(1) - done() - }) - - // check worker off function is ok - /** - * @tc.name: worker_off_test_002 - * @tc.desc: Removes an event listener to the worker. - * @tc.author: hanyuqing - */ - it('worker_off_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let zhangSanTimes = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.on("zhangsan", ()=>{ - zhangSanTimes++ - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangSanTimes).assertEqual(2) - - for (let i=0;i<3;i++) - { - ss.off("zhangsan") - } - - ss.dispatchEvent({type: "zhangsan"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(zhangSanTimes).assertEqual(2) - done() - }) - - // check worker removeEventListener function is ok - /** - * @tc.name: worker_removeListener_test_001 - * @tc.desc: Removes an event defined for the worker. - * @tc.author: hanyuqing - */ - it('worker_removeListener_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let zhangSanTimes = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.addEventListener("zhangsan", ()=>{ - zhangSanTimes++ - }) - - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangSanTimes).assertEqual(1) - - ss.removeEventListener("zhangsan") - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(zhangSanTimes).assertEqual(1) - done() - }) - - // check worker removeEventListener function is ok - /** - * @tc.name: worker_removeListener_test_002 - * @tc.desc: Removes an event defined for the worker. - * @tc.author: hanyuqing - */ - it('worker_removeListener_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let zhangSanTimes = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.addEventListener("zhangsan", ()=>{ - zhangSanTimes++ - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangSanTimes).assertEqual(2) - - for (let i=0;i<3;i++) - { - ss.removeEventListener("zhangsan") - } - - ss.dispatchEvent({type: "zhangsan"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(zhangSanTimes).assertEqual(2) - done() - }) - - // check worker removeAllListener function is ok - /** - * @tc.name: worker_removeListener_test_003 - * @tc.desc: Removes an event defined for the worker. - * @tc.author: hanyuqing - */ - it('worker_removeListener_test_003', 0, async function (done) { - let ss = new worker.Worker("workers/worker.js") - - let zhangSanTimes = 0 - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.addEventListener("zhangsan", ()=>{ - zhangSanTimes++ - }) - - let liSiTimes = 0 - ss.addEventListener("lisi", ()=>{ - liSiTimes++ - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangSanTimes).assertEqual(2) - - ss.dispatchEvent({type: "lisi"}) - ss.dispatchEvent({type: "lisi"}) - expect(liSiTimes).assertEqual(2) - - ss.removeAllListener() - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangSanTimes).assertEqual(2) - - ss.dispatchEvent({type: "lisi"}) - ss.dispatchEvent({type: "lisi"}) - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(liSiTimes).assertEqual(2) - done() - }) - - // check parentPort.close is ok - /** - * @tc.name: worker_parentPortClose_test_001 - * @tc.desc: Close the worker thread to stop the worker from receiving messages. - * @tc.author: hanyuqing - */ - it('worker_parentPortClose_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker_008.js") - let res = 0 - let flag = false - - ss.onexit = function (e) { - res++ - flag = true - } - - ss.postMessage("abc") - while (!flag) { - await promiseCase() - } - - expect(res).assertEqual(1) - done() - }) - - // check parentPort.close is ok - /** - * @tc.name: worker_parentPortClose_test_002 - * @tc.desc: Close the worker thread to stop the worker from receiving messages. - * @tc.author: hanyuqing - */ - it('worker_parentPortClose_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker_008.js") - let res = 0 - let flag = false - - ss.onexit = function () { - flag = true - } - - ss.onmessage = function (e) { - res++ - } - - ss.postMessage("abc") - while (!flag) { - await promiseCase() - } - - ss.postMessage("hello") - await promiseCase() - expect(res).assertEqual(0) - done() - }) - - // check onmessageerror is ok - /** - * @tc.name: worker_onmessageerror_test_001 - * @tc.desc: The onmessage attribute of the worker specifies the event handler when the worker receives - a message that cannot be serialized. The event handler is executed in the host thread - * @tc.author: hanyuqing - */ - it('worker_onmessageerror_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker_008.js") - let res = 0 - let flag = false - - ss.onexit = function () { - flag = true - } - - ss.onmessageerror = function (e) { - res++ - } - - ss.postMessage("abc") - while (!flag) { - await promiseCase() - } - expect(res).assertEqual(0) - done() - }) - - // check onmessageerror is ok - /** - * @tc.name: worker_onmessageerror_test_002 - * @tc.desc: The onmessage attribute of the worker specifies the event handler when the worker receives - a message that cannot be serialized. The event handler is executed in the host thread - * @tc.author: hanyuqing - */ - it('worker_onmessageerror_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker_008.js") - let res = 0 - let flag = false - - ss.onexit = function() { - flag = true - res++ - } - - ss.onmessageerror = function (e) { - flag = true - } - function foo() { - } - ss.postMessage(foo) - while (!flag) { - await promiseCase() - } - - expect(res).assertEqual(1) - done() - }) - - // check new second worker is ok - /** - * @tc.name: worker_new_second_worker_test_001 - * @tc.desc: Create a second worker. - * @tc.author: hanyuqing - */ - it('worker_new_second_worker_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker_009.js") - let flag = false - let res = undefined - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - - ss.onmessage = function (e) { - flag = true - res = e.data - } - - ss.postMessage({type: "new", value: 12}) - while (!flag) { - console.log("worker:: foo wait") - await promiseCase() - } - - console.log("worker:: " + res) - expect(res).assertTrue() - - flag = false - ss.postMessage({type: "terminate"}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - done() - }) - - // check new third worker is ok - /** - * @tc.name: worker_new_second_worker_test_002 - * @tc.desc: Create a third worker. - * @tc.author: hanyuqing - */ - it('worker_new_second_worker_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker_012.js") - let flag = false - let res = undefined - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.onmessage = function (e) { - flag = true - res = e.data - } - - ss.onerror = function(ee) { - console.log("worker:: " + ee.message) - } - - ss.postMessage({type: "new", value: 12}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - expect(res).assertTrue() - - flag = false - ss.postMessage({type: "terminate"}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - done() - }) - - // check second worker postMessage number is ok - /** - * @tc.name: worker_second_worker_postMessage_test_001 - * @tc.desc: Check if the postMessage function of the second worker is ok. - * @tc.author: hanyuqing - */ - it('worker_second_worker_postMessage_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker_010.js") - let flag = false - let res = undefined - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.onmessage = function (e) { - flag = true - res = e.data - } - - ss.onerror = function(ee) { - console.log("worker:: " + ee.message) - } - - ss.postMessage({type: "new", value: 12}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - expect(res).assertEqual(25) - - flag = false - ss.postMessage({type: "terminate"}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - done() - }) - - // check second worker postMessage string is ok - /** - * @tc.name: worker_second_worker_postMessage_test_002 - * @tc.desc: Check if the postMessage function of the second worker is ok. - * @tc.author: hanyuqing - */ - it('worker_second_worker_postMessage_test_002', 0, async function (done) { - let ss = new worker.Worker("workers/worker_013.js") - let flag = false - let res = undefined - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.onmessage = function (e) { - flag = true - res = e.data - } - - ss.onerror = function(ee) { - console.log("worker:: " + ee.message) - } - - ss.postMessage({type: "new", value: "hello world"}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - expect(res).assertEqual("hello world worker") - - flag = false - ss.postMessage({type: "terminate"}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - done() - }) - - // check second worker postMessage array is ok - /** - * @tc.name: worker_second_worker_postMessage_test_003 - * @tc.desc: Check if the postMessage function of the second worker is ok. - * @tc.author: hanyuqing - */ - it('worker_second_worker_postMessage_test_003', 0, async function (done) { - let ss = new worker.Worker("workers/worker_014.js") - let flag = false - let res = undefined - let isTerminate = false - - ss.onexit = function () { - isTerminate = true - } - ss.onmessage = function (e) { - flag = true - res = e.data - } - - ss.onerror = function(ee) { - console.log("worker:: " + ee.message) - } - - ss.postMessage({type: "new", value: [1, 2]}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - expect(res[0]).assertEqual(2) - expect(res[1]).assertEqual(2) - - flag = false - ss.postMessage({type: "terminate"}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - done() - }) - - // check third worker postMessage is ok - /** - * @tc.name: worker_third_worker_postMessage_test_001 - * @tc.desc: Check if the postMessage function of the third worker is ok. - * @tc.author: hanyuqing - */ - it('worker_third_worker_postMessage_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker_015.js") - let flag = false - let res = undefined - let isTerminate = false - - ss.onexit = function() { - isTerminate = true - } - ss.onmessage = function(e) { - flag = true - res = e.data - } - ss.onerror = function(ee) { - console.log("worker:: " + ee.message) - } - - ss.postMessage({type: "new", value: 10}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(res).assertEqual(16) - - done() - }) - - // check second worker terminate is ok - /** - * @tc.name: worker_second_worker_terminate_test_001 - * @tc.desc: Check if the terminate function of the second worker is ok. - * @tc.author: hanyuqing - */ - it('worker_second_worker_terminate_test_001', 0, async function (done) { - let ss = new worker.Worker("workers/worker_011.js") - let flag = false - let res = undefined - let isTerminate = false - - ss.onexit = function() { - isTerminate = true - } - - ss.onmessage = function(e) { - flag = true - res = e.data - } - - ss.onerror = function(ee) { - console.log("worker:: " + ee.message) - } - - ss.postMessage({type: "new", value: 12}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - - flag = false - ss.postMessage({type: "terminate"}) - while (!flag) { - ss.postMessage({type: "wait"}) - await promiseCase() - } - - ss.terminate() - while (!isTerminate) { - await promiseCase() - } - - expect(res).assertEqual("terminate") - done() - }) -}) +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" +export default function WorkerTest() { +describe('WorkerTest', function () { + + afterAll(function () { + console.info('total case over') + }) + + function promiseCase() { + let p = new Promise(function (resolve, reject) { + setTimeout(function () { + resolve(0) + }, 100) + }).then(undefined, (error) => { + }) + return p + } + + /** + * @tc.name: worker_constructor_test_001 + * @tc.desc: worker constructor to Creates a worker instance. + * @tc.author: hanyuqing + */ + it('worker_constructor_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + + expect(ss != null).assertTrue() + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + /** + * @tc.name: worker_constructor_test_002 + * @tc.desc: worker constructor to Creates a worker instance. + * @tc.author: hanyuqing + */ + it('worker_constructor_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js", {name:"1st worker", shared: false}) + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + + expect(ss != null).assertTrue() + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + /** + * @tc.name: worker_constructor_test_003 + * @tc.desc: worker constructor to Creates a worker instance. + * @tc.author: hanyuqing + */ + it('worker_constructor_test_003', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js", {type:"classic", name:"2st worker", shared: false}) + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + + expect(ss != null).assertTrue() + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + /** + * @tc.name: worker_constructor_test_004 + * @tc.desc: worker constructor to Creates a worker instance. + * @tc.author: hanyuqing + */ + it('worker_constructor_test_004', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js", {type:"classic", name:"3st worker", shared: true}) + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + + expect(ss != null).assertTrue() + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + // check postMessage is ok + // main post "hello world", will receive "hello world worker" + /** + * @tc.name: worker_postMessage_test_001 + * @tc.desc: Sends a message to the worker thread. + * @tc.author: hanyuqing + */ + it('worker_postMessage_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_002.js") + + let res = undefined + let flag = false + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.onmessage = function (e) { + res = e.data + flag = true + } + + ss.postMessage("hello world") + while (!flag) { + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(res).assertEqual("hello world worker") + done() + }) + + // check postMessage is ok + // main post 12 , will receive 12 * 2 + 1 + /** + * @tc.name: worker_postMessage_test_002 + * @tc.desc: Sends a message to the worker thread. + * @tc.author: hanyuqing + */ + it('worker_postMessage_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_003.js") + + let res = undefined + let flag = false + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.onmessage = function (e) { + res = e.data + flag = true + } + + ss.postMessage(12) + while (!flag) { + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(res).assertEqual(25) + done() + }) + + // check postMessage is ok + // main post {message:"hello world"} , will receive {message:"hello world worker"} + /** + * @tc.name: worker_postMessage_test_003 + * @tc.desc: Sends a message to the worker thread. + * @tc.author: hanyuqing + */ + it('worker_postMessage_test_003', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_004.js") + + let res = undefined + let flag = false + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.onmessage = function (e) { + res = e.data.message + flag = true + } + + ss.postMessage({"message":"hello world"}) + while (!flag) { + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(res).assertEqual("hello world worker") + done() + }) + + // check worker name is ok + /** + * @tc.name: worker_postMessage_test_004 + * @tc.desc: Sends a message to the worker thread. + * @tc.author: hanyuqing + */ + it('worker_postMessage_test_004', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_005.js", {name: "zhangsan"}) + + let res = undefined + let flag = false + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.onmessage = function (e) { + res = e.data + console.info("worker:: type " + e.type) + console.info("worker:: timeStamp " + e.timeStamp) + flag = true + } + + ss.postMessage("hello world") + while (!flag) { + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(res).assertEqual("zhangsan") + done() + }) + + // check worker transfer buffer is ok + /** + * @tc.name: worker_postMessage_test_005 + * @tc.desc: Sends a message to the worker thread. + * @tc.author: hanyuqing + */ + it('worker_postMessage_test_005', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_006.js") + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + + const buffer = new ArrayBuffer(8) + expect(buffer.byteLength).assertEqual(8) + ss.postMessage(buffer, [buffer]) + let length = undefined + let exception = undefined + try { + length = buffer.byteLength + } catch (e) { + exception = e.message + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + console.log("worker:: length is " + length) + console.log("worker:: exception is " + exception) + + if (typeof exception == "undefined") { + expect(length).assertEqual(0) + } else { + expect(exception).assertEqual("IsDetachedBuffer") + } + done() + }) + + // check worker handle error is ok + /** + * @tc.name: worker_postMessage_test_006 + * @tc.desc: Sends a message to the worker thread. + * @tc.author: hanyuqing + */ + it('worker_postMessage_test_006', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_007.js") + + let res = undefined + let flag = false + let isTerminate = false + + ss.onerror = function (e) { + res = e.message + console.info("worker:: filename " + e.filename) + console.info("worker:: lineno " + e.lineno) + console.info("worker:: colno " + e.colno) + console.info("worker:: error " + e.error) + flag = true + } + ss.onexit = function () { + isTerminate = true + } + + ss.postMessage("hello world") + while (!flag) { + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(res).assertEqual("Error: 123") + done() + }) + + // check worker terminate is ok + /** + * @tc.name: worker_terminate_test_001 + * @tc.desc: Terminates the worker thread to stop the worker from receiving messages. + * @tc.author: hanyuqing + */ + it('worker_terminate_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + let res = 0 + let flag = false + + ss.onexit = function () { + flag = true + res++ + } + + ss.terminate() + while (!flag) { + await promiseCase() + } + + expect(res).assertEqual(1) + done() + }) + + // check worker terminate is ok + /** + * @tc.name: worker_terminate_test_002 + * @tc.desc: Terminates the worker thread to stop the worker from receiving messages. + * @tc.author: hanyuqing + */ + it('worker_terminate_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + let res = 0 + let flag = false + + ss.onexit = function () { + flag = true + res++ + } + + // Repeated execution terminate + ss.terminate() + ss.terminate() + + while (!flag) { + await promiseCase() + } + + expect(res).assertEqual(1) + done() + }) + + // check worker terminate is ok + /** + * @tc.name: worker_terminate_test_003 + * @tc.desc: Terminates the worker thread to stop the worker from receiving messages. + * @tc.author: hanyuqing + */ + it('worker_terminate_test_003', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + let res = 0 + let flag = false + + ss.onexit = function () { + flag = true + res++ + } + ss.onmessage = function (e) { + res++ + } + + ss.terminate() + while (!flag) { + await promiseCase() + } + expect(res).assertEqual(1) + + ss.postMessage("hello world") + await promiseCase() + expect(res).assertEqual(1) + done() + }) + + // check worker on function is ok + /** + * @tc.name: worker_on_test_001 + * @tc.desc: Adds an event listener to the worker. + * @tc.author: hanyuqing + */ + it('worker_on_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let times = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.on("zhangsan", ()=>{ + times++ + }) + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(times).assertEqual(1) + done() + }) + + // check worker on function is ok + /** + * @tc.name: worker_on_test_002 + * @tc.desc: Adds an event listener to the worker. + * @tc.author: hanyuqing + */ + it('worker_on_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let times = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.on("zhangsan", ()=>{ + times-- + }) + ss.on("lisi", ()=>{ + times++ + }) + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(times).assertEqual(0) + done() + }) + + // check worker on function is ok + /** + * @tc.name: worker_on_test_003 + * @tc.desc: Adds an event listener to the worker. + * @tc.author: hanyuqing + */ + it('worker_on_test_003', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let times = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.on("zhangsan", ()=>{ + times++ + }) + + for (let i=0;i<10;i++) + { + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + console.log("times " + times) + expect(times).assertEqual(10) + done() + }) + + // check worker once function is ok + /** + * @tc.name: worker_once_test_001 + * @tc.desc: Adds an event listener to the worker and removes the event listener automically + after it is invoked once. + * @tc.author: hanyuqing + */ + it('worker_once_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let times = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.once("zhangsan", ()=>{ + times++ + }) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(times).assertEqual(1) + done() + }) + + // check worker once function is ok + /** + * @tc.name: worker_once_test_002 + * @tc.desc: Adds an event listener to the worker and removes the event listener automically + after it is invoked once. + * @tc.author: hanyuqing + */ + it('worker_once_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let times = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.once("zhangsan", ()=>{ + times++ + }) + + for (let i=0;i<10;i++) + { + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(times).assertEqual(1) + done() + }) + + /** + * @tc.name: worker_once_test_003 + * @tc.desc: Adds an event listener to the worker and removes the event listener automically + after it is invoked once. + * @tc.author: hanyuqing + */ + it('worker_once_test_003', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let times = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.once("zhangsan", ()=>{ + times-- + }) + + ss.once("lisi", ()=>{ + times++ + }) + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(times).assertEqual(0) + done() + }) + + // check worker addEventListener function is ok + /** + * @tc.name: worker_addEventListener_test_001 + * @tc.desc: Add an event listener to the Worker. + * @tc.author: hanyuqing + */ + it('worker_addEventListener_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let times = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.addEventListener("zhangsan", ()=>{ + times++ + }) + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(times).assertEqual(2) + done() + }) + + // check worker addEventListener function is ok + /** + * @tc.name: worker_addEventListener_test_002 + * @tc.desc: Add an event listener to the Worker. + * @tc.author: hanyuqing + */ + it('worker_addEventListener_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let times = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.addEventListener("zhangsan", ()=>{ + times++ + }) + ss.addEventListener("lisi", ()=>{ + times++ + }) + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(times).assertEqual(2) + done() + }) + + // check worker addEventListener function is ok + /** + * @tc.name: worker_addEventListener_test_003 + * @tc.desc: Add an event listener to the Worker. + * @tc.author: hanyuqing + */ + it('worker_addEventListener_test_003', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let times = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.addEventListener("zhangsan", ()=>{ + times++ + }) + + for (let i=0;i<10;i++) + { + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(times).assertEqual(10) + done() + }) + + // check worker off function is ok + /** + * @tc.name: worker_off_test_001 + * @tc.desc: Removes an event listener to the worker. + * @tc.author: hanyuqing + */ + it('worker_off_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let zhangSanTimes = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.on("zhangsan", ()=>{ + zhangSanTimes++ + }) + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + expect(zhangSanTimes).assertEqual(1) + + ss.off("zhangsan") + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(zhangSanTimes).assertEqual(1) + done() + }) + + // check worker off function is ok + /** + * @tc.name: worker_off_test_002 + * @tc.desc: Removes an event listener to the worker. + * @tc.author: hanyuqing + */ + it('worker_off_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let zhangSanTimes = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.on("zhangsan", ()=>{ + zhangSanTimes++ + }) + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + expect(zhangSanTimes).assertEqual(2) + + for (let i=0;i<3;i++) + { + ss.off("zhangsan") + } + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(zhangSanTimes).assertEqual(2) + done() + }) + + // check worker removeEventListener function is ok + /** + * @tc.name: worker_removeListener_test_001 + * @tc.desc: Removes an event defined for the worker. + * @tc.author: hanyuqing + */ + it('worker_removeListener_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let zhangSanTimes = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.addEventListener("zhangsan", ()=>{ + zhangSanTimes++ + }) + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + expect(zhangSanTimes).assertEqual(1) + + ss.removeEventListener("zhangsan") + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(zhangSanTimes).assertEqual(1) + done() + }) + + // check worker removeEventListener function is ok + /** + * @tc.name: worker_removeListener_test_002 + * @tc.desc: Removes an event defined for the worker. + * @tc.author: hanyuqing + */ + it('worker_removeListener_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let zhangSanTimes = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.addEventListener("zhangsan", ()=>{ + zhangSanTimes++ + }) + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + expect(zhangSanTimes).assertEqual(2) + + for (let i=0;i<3;i++) + { + ss.removeEventListener("zhangsan") + } + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(zhangSanTimes).assertEqual(2) + done() + }) + + // check worker removeAllListener function is ok + /** + * @tc.name: worker_removeListener_test_003 + * @tc.desc: Removes an event defined for the worker. + * @tc.author: hanyuqing + */ + it('worker_removeListener_test_003', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker.js") + + let zhangSanTimes = 0 + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.addEventListener("zhangsan", ()=>{ + zhangSanTimes++ + }) + + let liSiTimes = 0 + ss.addEventListener("lisi", ()=>{ + liSiTimes++ + }) + + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + expect(zhangSanTimes).assertEqual(2) + + ss.dispatchEvent({type: "lisi", timeStamp: 0}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) + expect(liSiTimes).assertEqual(2) + + ss.removeAllListener() + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + ss.dispatchEvent({type: "zhangsan", timeStamp: 0}) + expect(zhangSanTimes).assertEqual(2) + + ss.dispatchEvent({type: "lisi", timeStamp: 0}) + ss.dispatchEvent({type: "lisi", timeStamp: 0}) + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(liSiTimes).assertEqual(2) + done() + }) + + // check parentPort.close is ok + /** + * @tc.name: worker_parentPortClose_test_001 + * @tc.desc: Close the worker thread to stop the worker from receiving messages. + * @tc.author: hanyuqing + */ + it('worker_parentPortClose_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_008.js") + let res = 0 + let flag = false + + ss.onexit = function (e) { + res++ + flag = true + } + + ss.postMessage("abc") + while (!flag) { + await promiseCase() + } + + expect(res).assertEqual(1) + done() + }) + + // check parentPort.close is ok + /** + * @tc.name: worker_parentPortClose_test_002 + * @tc.desc: Close the worker thread to stop the worker from receiving messages. + * @tc.author: hanyuqing + */ + it('worker_parentPortClose_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_008.js") + let res = 0 + let flag = false + + ss.onexit = function () { + flag = true + } + + ss.onmessage = function (e) { + res++ + } + + ss.postMessage("abc") + while (!flag) { + await promiseCase() + } + + ss.postMessage("hello") + await promiseCase() + expect(res).assertEqual(0) + done() + }) + + // check onmessageerror is ok + /** + * @tc.name: worker_onmessageerror_test_001 + * @tc.desc: The onmessage attribute of the worker specifies the event handler when the worker receives + a message that cannot be serialized. The event handler is executed in the host thread + * @tc.author: hanyuqing + */ + it('worker_onmessageerror_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_008.js") + let res = 0 + let flag = false + + ss.onexit = function () { + flag = true + } + + ss.onmessageerror = function (e) { + res++ + } + + ss.postMessage("abc") + while (!flag) { + await promiseCase() + } + expect(res).assertEqual(0) + done() + }) + + // check onmessageerror is ok + /** + * @tc.name: worker_onmessageerror_test_002 + * @tc.desc: The onmessage attribute of the worker specifies the event handler when the worker receives + a message that cannot be serialized. The event handler is executed in the host thread + * @tc.author: hanyuqing + */ + it('worker_onmessageerror_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_008.js") + let res = 0 + let flag = false + + ss.onexit = function() { + flag = true + res++ + } + + ss.onmessageerror = function (e) { + flag = true + } + function foo() { + } + ss.postMessage(foo) + while (!flag) { + await promiseCase() + } + + expect(res).assertEqual(1) + done() + }) + + // check new second worker is ok + /** + * @tc.name: worker_new_second_worker_test_001 + * @tc.desc: Create a second worker. + * @tc.author: hanyuqing + */ + it('worker_new_second_worker_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_009.js") + let flag = false + let res = undefined + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + + ss.onmessage = function (e) { + flag = true + res = e.data + } + + ss.postMessage({type: "new", value: 12}) + while (!flag) { + console.log("worker:: foo wait") + await promiseCase() + } + + console.log("worker:: " + res) + expect(res).assertTrue() + + flag = false + ss.postMessage({type: "terminate"}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + // check new third worker is ok + /** + * @tc.name: worker_new_second_worker_test_002 + * @tc.desc: Create a third worker. + * @tc.author: hanyuqing + */ + it('worker_new_second_worker_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_012.js") + let flag = false + let res = undefined + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.onmessage = function (e) { + flag = true + res = e.data + } + + ss.onerror = function(ee) { + console.log("worker:: " + ee.message) + } + + ss.postMessage({type: "new", value: 12}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + expect(res).assertTrue() + + flag = false + ss.postMessage({type: "terminate"}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + // check second worker postMessage number is ok + /** + * @tc.name: worker_second_worker_postMessage_test_001 + * @tc.desc: Check if the postMessage function of the second worker is ok. + * @tc.author: hanyuqing + */ + it('worker_second_worker_postMessage_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_010.js") + let flag = false + let res = undefined + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.onmessage = function (e) { + flag = true + res = e.data + } + + ss.onerror = function(ee) { + console.log("worker:: " + ee.message) + } + + ss.postMessage({type: "new", value: 12}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + expect(res).assertEqual(25) + + flag = false + ss.postMessage({type: "terminate"}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + // check second worker postMessage string is ok + /** + * @tc.name: worker_second_worker_postMessage_test_002 + * @tc.desc: Check if the postMessage function of the second worker is ok. + * @tc.author: hanyuqing + */ + it('worker_second_worker_postMessage_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_013.js") + let flag = false + let res = undefined + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.onmessage = function (e) { + flag = true + res = e.data + } + + ss.onerror = function(ee) { + console.log("worker:: " + ee.message) + } + + ss.postMessage({type: "new", value: "hello world"}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + expect(res).assertEqual("hello world worker") + + flag = false + ss.postMessage({type: "terminate"}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + // check second worker postMessage array is ok + /** + * @tc.name: worker_second_worker_postMessage_test_003 + * @tc.desc: Check if the postMessage function of the second worker is ok. + * @tc.author: hanyuqing + */ + it('worker_second_worker_postMessage_test_003', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_014.js") + let flag = false + let res = undefined + let isTerminate = false + + ss.onexit = function () { + isTerminate = true + } + ss.onmessage = function (e) { + flag = true + res = e.data + } + + ss.onerror = function(ee) { + console.log("worker:: " + ee.message) + } + + ss.postMessage({type: "new", value: [1, 2]}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + expect(res[0]).assertEqual(2) + expect(res[1]).assertEqual(2) + + flag = false + ss.postMessage({type: "terminate"}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + // check third worker postMessage is ok + /** + * @tc.name: worker_third_worker_postMessage_test_001 + * @tc.desc: Check if the postMessage function of the third worker is ok. + * @tc.author: hanyuqing + */ + it('worker_third_worker_postMessage_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_015.js") + let flag = false + let res = undefined + let isTerminate = false + + ss.onexit = function() { + isTerminate = true + } + ss.onmessage = function(e) { + flag = true + res = e.data + } + ss.onerror = function(ee) { + console.log("worker:: " + ee.message) + } + + ss.postMessage({type: "new", value: 10}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(res).assertEqual(16) + + done() + }) + + // check second worker terminate is ok + /** + * @tc.name: worker_second_worker_terminate_test_001 + * @tc.desc: Check if the terminate function of the second worker is ok. + * @tc.author: hanyuqing + */ + it('worker_second_worker_terminate_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_011.js") + let flag = false + let res = undefined + let isTerminate = false + + ss.onexit = function() { + isTerminate = true + } + + ss.onmessage = function(e) { + flag = true + res = e.data + } + + ss.onerror = function(ee) { + console.log("worker:: " + ee.message) + } + + ss.postMessage({type: "new", value: 12}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + + flag = false + ss.postMessage({type: "terminate"}) + while (!flag) { + ss.postMessage({type: "wait"}) + await promiseCase() + } + + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + + expect(res).assertEqual("terminate") + done() + }) +}) } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_002.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_002.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_002.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_002.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_003.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_003.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_003.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_003.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_004.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_004.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_004.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_004.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_005.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_005.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_005.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_005.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_006.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_006.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_006.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_006.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_007.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_007.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_007.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_007.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_008.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_008.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_008.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_008.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_009.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_009.js similarity index 93% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_009.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_009.js index f7faf79f0..b78ba9d03 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_009.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_009.js @@ -23,7 +23,7 @@ parentPort.onmessage = function(e) { let data = e.data; switch(data.type) { case "new": - ss = new worker.ThreadWorker("workers/newworker_0091.js"); + ss = new worker.ThreadWorker("entry/ets/workers/newworker_0091.js"); console.log("worker:: workerxx "); ss.onexit = function() { flag = true; diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0091.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0091.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0091.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0091.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_010.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_010.js similarity index 94% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_010.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_010.js index 6bf86e119..9ef2534e2 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_010.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_010.js @@ -24,7 +24,7 @@ parentPort.onmessage = function(e) { let data = e.data; switch(data.type) { case "new": - ss = new worker.ThreadWorker("workers/newworker_0101.js"); + ss = new worker.ThreadWorker("entry/ets/workers/newworker_0101.js"); ss.onmessage = function(ee) { backValue = ee.data; flag = true; diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0101.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0101.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0101.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0101.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_011.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_011.js similarity index 94% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_011.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_011.js index db3a35dfa..13c3ca16a 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_011.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_011.js @@ -24,7 +24,7 @@ parentPort.onmessage = function(e) { let data = e.data; switch(data.type) { case "new": - ss = new worker.ThreadWorker("workers/newworker_0111.js"); + ss = new worker.ThreadWorker("entry/ets/workers/newworker_0111.js"); ss.onmessage = function(ee) { backValue = ee.data; flag = true; diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0111.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0111.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0111.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0111.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_012.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_012.js similarity index 94% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_012.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_012.js index 668733eb8..17486ae19 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_012.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_012.js @@ -24,7 +24,7 @@ parentPort.onmessage = function(e) { let data = e.data; switch(data.type) { case "new": - ss = new worker.ThreadWorker("workers/newworker_0121.js"); + ss = new worker.ThreadWorker("entry/ets/workers/newworker_0121.js"); ss.onmessage = function(ee) { backValue = ee.data; flag = true; diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0121.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0121.js similarity index 92% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0121.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0121.js index 89d902c55..64bc5371d 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0121.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0121.js @@ -24,7 +24,7 @@ parentPort.onmessage = function(e) { let data = e.data; switch(data.type) { case "new": - ss = new worker.ThreadWorker("workers/newworker_0122.js"); + ss = new worker.ThreadWorker("entry/ets/workers/newworker_0122.js"); ss.terminate(); ss.onexit = function() { parentPort.postMessage(ss != null); diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0122.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0122.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0122.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0122.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_013.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_013.js similarity index 94% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_013.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_013.js index 3d7f7bc93..2b469c0f3 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_013.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_013.js @@ -24,7 +24,7 @@ parentPort.onmessage = function(e) { var data = e.data; switch(data.type) { case "new": - ss = new worker.ThreadWorker("workers/newworker_0131.js"); + ss = new worker.ThreadWorker("entry/ets/workers/newworker_0131.js"); ss.onmessage = function(ee) { backValue = ee.data; flag = true; diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0131.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0131.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0131.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0131.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_014.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_014.js similarity index 94% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_014.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_014.js index e61c57533..f8c58bd66 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_014.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_014.js @@ -24,7 +24,7 @@ parentPort.onmessage = function(e) { let data = e.data; switch(data.type) { case "new": - ss = new worker.ThreadWorker("workers/newworker_0141.js"); + ss = new worker.ThreadWorker("entry/ets/workers/newworker_0141.js"); ss.onmessage = function(ee) { backValue = ee.data; flag = true; diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0141.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0141.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0141.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0141.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_015.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_015.js similarity index 94% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_015.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_015.js index 4fda2afa3..5ca488bc4 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_015.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_015.js @@ -24,7 +24,7 @@ parentPort.onmessage = function(e) { var data = e.data; switch(data.type) { case "new": - ss = new worker.ThreadWorker("workers/newworker_0151.js"); + ss = new worker.ThreadWorker("entry/ets/workers/newworker_0151.js"); ss.onexit = function() { parentPort.postMessage(backValue); // 16 } diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0151.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0151.js similarity index 94% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0151.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0151.js index 3a7ea98d1..06eac33ee 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0151.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0151.js @@ -24,7 +24,7 @@ parentPort.onmessage = function(e) { let data = e.data; switch(data.type) { case "new": - ss = new worker.ThreadWorker("workers/newworker_0152.js"); + ss = new worker.ThreadWorker("entry/ets/workers/newworker_0152.js"); ss.onexit = function() { parentPort.postMessage(backValue); // 16 } diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0152.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0152.js similarity index 100% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/newworker_0152.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/newworker_0152.js diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker.js index d7321f891..efa01a665 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker.js @@ -1,55 +1,55 @@ -/* - * 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 worker from '@ohos.worker'; -const parentPort = worker.parentPort; - -console.info("worker:: new version") - -parentPort.onclose = function() { - console.info("worker::worker.js onclose"); -} - -parentPort.onmessage = function(e) { - let data = e.data; - console.info("worker:: worker thread worker data is " + data.data); - switch(data.type) { - case "normal": - console.info("worker:: worker thread receive data " + data.data); - parentPort.postMessage(data); - console.info("worker:: worker thread post back"); - break; - case "error": - throw new Error("123"); - case "buffer": - console.info("worker:: worker.js receive buffer length is " + data.data.byteLength); - parentPort.postMessage(data, [data.data]); - console.info("worker:: worker.js post buffer length is " + data.data.byteLength); - break; - default: - console.info("worker:: worker.js receive unknow type"); - break - } -} - -// Deserialization error -parentPort.onmessageerror = function() { - console.info("worker:: worker.js onmessageerror"); -} - -// js execution error -parentPort.onerror = function(data) { - console.info("worker:: worker.js onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno); +/* + * 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 worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +console.info("worker:: new version") + +parentPort.onclose = function() { + console.info("worker::worker.js onclose"); +} + +parentPort.onmessage = function(e) { + let data = e.data; + console.info("worker:: worker thread worker data is " + data.data); + switch(data.type) { + case "normal": + console.info("worker:: worker thread receive data " + data.data); + parentPort.postMessage(data); + console.info("worker:: worker thread post back"); + break; + case "error": + throw new Error("123"); + case "buffer": + console.info("worker:: worker.js receive buffer length is " + data.data.byteLength); + parentPort.postMessage(data, [data.data]); + console.info("worker:: worker.js post buffer length is " + data.data.byteLength); + break; + default: + console.info("worker:: worker.js receive unknow type"); + break + } +} + +// Deserialization error +parentPort.onmessageerror = function() { + console.info("worker:: worker.js onmessageerror"); +} + +// js execution error +parentPort.onerror = function(data) { + console.info("worker:: worker.js onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno); } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_002.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_002.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_002.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_002.js index 75b1ccd3d..ab62c6d1f 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_002.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_002.js @@ -1,23 +1,23 @@ -/* - * 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 worker from '@ohos.worker'; -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - console.log("worker:: worker receive data " + e.data); - let data = e.data + " worker"; - parentPort.postMessage(data) +/* + * 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 worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + console.log("worker:: worker receive data " + e.data); + let data = e.data + " worker"; + parentPort.postMessage(data) } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_003.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_003.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_003.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_003.js index a45ecabfe..a38483d9c 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_003.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_003.js @@ -1,22 +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 worker from '@ohos.worker'; -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - let data = e.data * 2 + 1 - parentPort.postMessage(data) +/* + * 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 worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + let data = e.data * 2 + 1 + parentPort.postMessage(data) } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_004.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_004.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_004.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_004.js index 42bfc9191..21655d9c9 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_004.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_004.js @@ -1,23 +1,23 @@ -/* - * 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 worker from '@ohos.worker'; -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - let data = e.data; - data.message = "hello world " + "worker" - parentPort.postMessage(data) +/* + * 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 worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + let data = e.data; + data.message = "hello world " + "worker" + parentPort.postMessage(data) } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_005.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_005.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_005.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_005.js index 77679245e..8b96f3258 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_005.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_005.js @@ -1,21 +1,21 @@ -/* - * 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 worker from '@ohos.worker'; -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - parentPort.postMessage(name) +/* + * 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 worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + parentPort.postMessage(name) } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_006.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_006.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_006.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_006.js index fdd8d8783..39bf7bc02 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_006.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_006.js @@ -1,21 +1,21 @@ -/* - * 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 worker from '@ohos.worker'; -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - parentPort.postMessage("hello world") +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + parentPort.postMessage("hello world") } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_007.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_007.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_007.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_007.js index 6b7e100b6..93792ba86 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_007.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_007.js @@ -1,21 +1,21 @@ -/* - * 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 worker from '@ohos.worker'; -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - throw new Error(123) +/* + * 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 worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + throw new Error(123) } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_008.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_008.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_008.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_008.js index 13cb2ea9d..71cf35261 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_008.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_008.js @@ -1,22 +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 worker from '@ohos.worker'; -const parentPort = worker.parentPort; - -console.info("worker::" + typeof parentPort.self) -parentPort.onmessage = function(e) { - parentPort.close() -} +/* + * 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 worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +console.info("worker::" + typeof parentPort.self) +parentPort.onmessage = function(e) { + parentPort.close() +} diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_009.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_009.js similarity index 88% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_009.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_009.js index 905ec28ab..420c505fa 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_009.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_009.js @@ -1,45 +1,45 @@ -/* - * 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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -var ss = undefined; -var flag = false; - -parentPort.onmessage = function(e) { - let data = e.data; - switch(data.type) { - case "new": - ss = new worker.Worker("workers/worker_0091.js"); - console.log("worker:: workerxx "); - ss.onexit = function() { - flag = true; - } - parentPort.postMessage(ss != null); - break; - case "wait": - if (flag) { - parentPort.postMessage("terminate"); - } - break; - case "terminate": - flag = false; - ss.terminate(); - break; - default: - break; - } +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +var ss = undefined; +var flag = false; + +parentPort.onmessage = function(e) { + let data = e.data; + switch(data.type) { + case "new": + ss = new worker.Worker("entry/ets/workers/worker_0091.js"); + console.log("worker:: workerxx"); + ss.onexit = function() { + flag = true; + } + parentPort.postMessage(ss != null); + break; + case "wait": + if (flag) { + parentPort.postMessage("terminate"); + } + break; + case "terminate": + flag = false; + ss.terminate(); + break; + default: + break; + } } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0091.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0091.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0091.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0091.js index 940815ae3..a7a1ff89c 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0091.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0091.js @@ -1,21 +1,21 @@ -/* - * 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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - console.log("worker:: onmessage"); +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + console.log("worker:: onmessage"); } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_010.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_010.js similarity index 92% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_010.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_010.js index 73663f6cb..825585d18 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_010.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_010.js @@ -1,50 +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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -var ss = undefined; -var backValue = undefined; -var flag = false; - -parentPort.onmessage = function(e) { - let data = e.data; - switch(data.type) { - case "new": - ss = new worker.Worker("workers/worker_0101.js"); - ss.onmessage = function(ee) { - backValue = ee.data; - flag = true; - } - ss.onexit = function() { - backValue = "terminate"; - flag = true; - } - ss.postMessage(data.value); - break; - case "wait": - if (flag) { - parentPort.postMessage(backValue); - } - break; - case "terminate": - flag = false; - ss.terminate(); - break; - default: - break; - } +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +var ss = undefined; +var backValue = undefined; +var flag = false; + +parentPort.onmessage = function(e) { + let data = e.data; + switch(data.type) { + case "new": + ss = new worker.Worker("entry/ets/workers/worker_0101.js"); + ss.onmessage = function(ee) { + backValue = ee.data; + flag = true; + } + ss.onexit = function() { + backValue = "terminate"; + flag = true; + } + ss.postMessage(data.value); + break; + case "wait": + if (flag) { + parentPort.postMessage(backValue); + } + break; + case "terminate": + flag = false; + ss.terminate(); + break; + default: + break; + } } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0101.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0101.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0101.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0101.js index 41f5e9940..9cc4eaeed 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0101.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0101.js @@ -1,22 +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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - let data = e.data; // 12 - parentPort.postMessage(data * 2 + 1); // 25 +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + let data = e.data; // 12 + parentPort.postMessage(data * 2 + 1); // 25 } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_011.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_011.js similarity index 92% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_011.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_011.js index 89d05c4a8..b4a5ff4f4 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_011.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_011.js @@ -1,50 +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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -var ss = undefined; -var backValue = undefined; -var flag = false; - -parentPort.onmessage = function(e) { - let data = e.data; - switch(data.type) { - case "new": - ss = new worker.Worker("workers/worker_0111.js"); - ss.onmessage = function(ee) { - backValue = ee.data; - flag = true; - } - ss.onexit = function(code) { - backValue = "terminate"; - flag = true; - } - ss.postMessage(data.value); - break; - case "wait": - if (flag) { - parentPort.postMessage(backValue); - } - break; - case "terminate": - flag = false; - ss.terminate(); - break; - default: - break; - } +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +var ss = undefined; +var backValue = undefined; +var flag = false; + +parentPort.onmessage = function(e) { + let data = e.data; + switch(data.type) { + case "new": + ss = new worker.Worker("entry/ets/workers/worker_0111.js"); + ss.onmessage = function(ee) { + backValue = ee.data; + flag = true; + } + ss.onexit = function(code) { + backValue = "terminate"; + flag = true; + } + ss.postMessage(data.value); + break; + case "wait": + if (flag) { + parentPort.postMessage(backValue); + } + break; + case "terminate": + flag = false; + ss.terminate(); + break; + default: + break; + } } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0111.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0111.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0111.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0111.js index b105de7ec..d06da03b8 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0111.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0111.js @@ -1,22 +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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - console.log("worker:: onmessage") - parentPort.postMessage("terminate"); +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + console.log("worker:: onmessage") + parentPort.postMessage("terminate"); } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_012.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_012.js similarity index 92% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_012.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_012.js index d58f06088..acd33e7cc 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_012.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_012.js @@ -1,50 +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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -var ss = undefined; -var backValue = undefined; -var flag = false; - -parentPort.onmessage = function(e) { - let data = e.data; - switch(data.type) { - case "new": - ss = new worker.Worker("workers/worker_0121.js"); - ss.onmessage = function(ee) { - backValue = ee.data; - flag = true; - } - ss.onexit = function() { - backValue = "terminate"; - flag = true; - } - ss.postMessage({type: "new"}); - break; - case "wait": - if (flag) { - parentPort.postMessage(backValue); - } - break; - case "terminate": - flag = false; - ss.terminate(); - break; - default: - break; - } +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +var ss = undefined; +var backValue = undefined; +var flag = false; + +parentPort.onmessage = function(e) { + let data = e.data; + switch(data.type) { + case "new": + ss = new worker.Worker("entry/ets/workers/worker_0121.js"); + ss.onmessage = function(ee) { + backValue = ee.data; + flag = true; + } + ss.onexit = function() { + backValue = "terminate"; + flag = true; + } + ss.postMessage({type: "new"}); + break; + case "wait": + if (flag) { + parentPort.postMessage(backValue); + } + break; + case "terminate": + flag = false; + ss.terminate(); + break; + default: + break; + } } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0121.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0121.js similarity index 91% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0121.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0121.js index 8cb3c2c63..52fe70ada 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0121.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0121.js @@ -1,36 +1,36 @@ -/* - * 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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -var ss = undefined; -var backValue = undefined; -var flag = false; - -parentPort.onmessage = function(e) { - let data = e.data; - switch(data.type) { - case "new": - ss = new worker.Worker("workers/worker_0122.js"); - ss.terminate(); - ss.onexit = function() { - parentPort.postMessage(ss != null); - } - break; - default: - break; - } +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +var ss = undefined; +var backValue = undefined; +var flag = false; + +parentPort.onmessage = function(e) { + let data = e.data; + switch(data.type) { + case "new": + ss = new worker.Worker("entry/ets/workers/worker_0122.js"); + ss.terminate(); + ss.onexit = function() { + parentPort.postMessage(ss != null); + } + break; + default: + break; + } } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0122.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0122.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0122.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0122.js index 48bc6bedd..e875140b6 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0122.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0122.js @@ -1,25 +1,25 @@ -/* - * 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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -var ss = undefined; -var backValue = undefined; -var flag = false; - -parentPort.onmessage = function(e) { - console.info("worker:: thrid worker onmessage") +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +var ss = undefined; +var backValue = undefined; +var flag = false; + +parentPort.onmessage = function(e) { + console.info("worker:: thrid worker onmessage") } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_013.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_013.js similarity index 92% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_013.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_013.js index 319081fcd..4796b39df 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_013.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_013.js @@ -1,50 +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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -var ss = undefined; -var backValue = undefined; -var flag = false; - -parentPort.onmessage = function(e) { - var data = e.data; - switch(data.type) { - case "new": - ss = new worker.Worker("workers/worker_0131.js"); - ss.onmessage = function(ee) { - backValue = ee.data; - flag = true; - } - ss.onexit = function() { - backValue = "terminate"; - flag = true; - } - ss.postMessage(data.value); - break; - case "wait": - if (flag) { - parentPort.postMessage(backValue); - } - break; - case "terminate": - flag = false; - ss.terminate(); - break; - default: - break; - } +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +var ss = undefined; +var backValue = undefined; +var flag = false; + +parentPort.onmessage = function(e) { + var data = e.data; + switch(data.type) { + case "new": + ss = new worker.Worker("entry/ets/workers/worker_0131.js"); + ss.onmessage = function(ee) { + backValue = ee.data; + flag = true; + } + ss.onexit = function() { + backValue = "terminate"; + flag = true; + } + ss.postMessage(data.value); + break; + case "wait": + if (flag) { + parentPort.postMessage(backValue); + } + break; + case "terminate": + flag = false; + ss.terminate(); + break; + default: + break; + } } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0131.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0131.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0131.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0131.js index 9236f010c..0004da328 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0131.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0131.js @@ -1,22 +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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - let data = e.data; // hello world - parentPort.postMessage(data + " worker"); // hello world worker +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + let data = e.data; // hello world + parentPort.postMessage(data + " worker"); // hello world worker } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_014.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_014.js similarity index 92% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_014.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_014.js index cf79c83ab..eede4debb 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_014.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_014.js @@ -1,50 +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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -var ss = undefined; -var backValue = undefined; -var flag = false; - -parentPort.onmessage = function(e) { - let data = e.data; - switch(data.type) { - case "new": - ss = new worker.Worker("workers/worker_0141.js"); - ss.onmessage = function(ee) { - backValue = ee.data; - flag = true; - } - ss.onexit = function() { - backValue = "terminate"; - flag = true; - } - ss.postMessage(data.value); - break; - case "wait": - if (flag) { - parentPort.postMessage(backValue); - } - break; - case "terminate": - flag = false; - ss.terminate(); - break; - default: - break; - } +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +var ss = undefined; +var backValue = undefined; +var flag = false; + +parentPort.onmessage = function(e) { + let data = e.data; + switch(data.type) { + case "new": + ss = new worker.Worker("entry/ets/workers/worker_0141.js"); + ss.onmessage = function(ee) { + backValue = ee.data; + flag = true; + } + ss.onexit = function() { + backValue = "terminate"; + flag = true; + } + ss.postMessage(data.value); + break; + case "wait": + if (flag) { + parentPort.postMessage(backValue); + } + break; + case "terminate": + flag = false; + ss.terminate(); + break; + default: + break; + } } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0141.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0141.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0141.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0141.js index ba9cbdba0..c8d5b7d7b 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0141.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0141.js @@ -1,23 +1,23 @@ -/* - * 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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - let data = e.data; - data[0] += 1 - parentPort.postMessage(data); // [2, 2] +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + let data = e.data; + data[0] += 1 + parentPort.postMessage(data); // [2, 2] } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_015.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_015.js similarity index 92% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_015.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_015.js index 74bd55530..3a400344f 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_015.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_015.js @@ -1,46 +1,46 @@ -/* - * 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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -var ss = undefined; -var backValue = undefined; -var flag = false; - -parentPort.onmessage = function(e) { - var data = e.data; - switch(data.type) { - case "new": - ss = new worker.Worker("workers/worker_0151.js"); - ss.onexit = function() { - parentPort.postMessage(backValue); // 16 - } - ss.onmessage = function(ee) { - backValue = ee.data; // 16 - flag = true; - } - ss.postMessage({type: "new", value: data.value + 1}); // 11 - break; - case "wait": - ss.postMessage({type: "wait"}); - if (flag) { - ss.terminate(); - } - break; - default: - break; - } +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +var ss = undefined; +var backValue = undefined; +var flag = false; + +parentPort.onmessage = function(e) { + var data = e.data; + switch(data.type) { + case "new": + ss = new worker.Worker("entry/ets/workers/worker_0151.js"); + ss.onexit = function() { + parentPort.postMessage(backValue); // 16 + } + ss.onmessage = function(ee) { + backValue = ee.data; // 16 + flag = true; + } + ss.postMessage({type: "new", value: data.value + 1}); // 11 + break; + case "wait": + ss.postMessage({type: "wait"}); + if (flag) { + ss.terminate(); + } + break; + default: + break; + } } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0151.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0151.js similarity index 92% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0151.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0151.js index eb827e0a5..4a47d69db 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0151.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0151.js @@ -1,45 +1,45 @@ -/* - * 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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -var ss = undefined; -var backValue = undefined; -var flag = false; - -parentPort.onmessage = function(e) { - let data = e.data; - switch(data.type) { - case "new": - ss = new worker.Worker("workers/worker_0152.js"); - ss.onexit = function() { - parentPort.postMessage(backValue); // 16 - } - ss.onmessage = function(ee) { - backValue = ee.data; - flag = true; - } - ss.postMessage(data.value + 2); // 13 - break; - case "wait": - if (flag) { - ss.terminate(); - } - break; - default: - break; - } +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +var ss = undefined; +var backValue = undefined; +var flag = false; + +parentPort.onmessage = function(e) { + let data = e.data; + switch(data.type) { + case "new": + ss = new worker.Worker("entry/ets/workers/worker_0152.js"); + ss.onexit = function() { + parentPort.postMessage(backValue); // 16 + } + ss.onmessage = function(ee) { + backValue = ee.data; + flag = true; + } + ss.postMessage(data.value + 2); // 13 + break; + case "wait": + if (flag) { + ss.terminate(); + } + break; + default: + break; + } } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0152.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0152.js similarity index 97% rename from commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0152.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0152.js index 57b52d0f1..ea073a604 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/MainAbility/workers/worker_0152.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_0152.js @@ -1,22 +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 worker from "@ohos.worker" - -const parentPort = worker.parentPort; - -parentPort.onmessage = function(e) { - let data = e.data; - parentPort.postMessage(data + 3); // 16 +/* + * 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 worker from "@ohos.worker" + +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + let data = e.data; + parentPort.postMessage(data + 3); // 16 } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/module.json b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/module.json new file mode 100644 index 000000000..666911d2b --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/module.json @@ -0,0 +1,40 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "com.example.workertest.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/element/color.json b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/element/color.json new file mode 100644 index 000000000..1bbc9aa96 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/element/string.json b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/element/string.json new file mode 100644 index 000000000..b8416b237 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "form_FormAbility_desc", + "value": "form_description" + }, + { + "name": "form_FormAbility_label", + "value": "form_label" + } + ] +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/media/icon.png b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(kzvMZ^(@4fD_{QVu$(&K6H|C37TG1Am9Re{<<3gd zh@`>;BqkXMW&p0T6rt|iB$)~CvFe(XC)F9WgAZn*0@t$oZo;!*}r@_`h?KKH&6A@3= zISXoQB+~`op>NP-buiA*^0n{@i{_?MRG)&k)c)k_F+-2Lud!S9pc+i`s74NpBCaGF zXN+pHkubw*msGBTY27BKHv)RRh3;nMg4&$fD_6X9Vt~;_4D+5XPH~#Kn-yjcy!$}1 zigv#FNY>TqMhtIBb@UoF!cE~Q8~;!Pek>SQQwHnHuWKoVBosAiOr}q>!>aE*Krc)V zBUMEcJ5NU0g8}-h6i1zpMY9>m4ne?=U2~`w7K7Q0gB_=p@$5K7p6}thw z-~3dMj?YNX2X$lZ+7ngQ$=s}3mizNN@kE%OtB)?c&i~2L55z8^=yz;xMHLmlY>&Q# zJj?!)M#q_SyfkQh)k?j8IfLtB)ZCp|*vf4_B zos?73yd^h-Ac+;?E4*bpf=o*^3x3-`TVjbY4n6!EN10K6o@fxdyps05Vo3PU)otB} z`3kR+2w7_C#8Z!q`J)p{Vh!+m9-UP!$STp+Hb}}#@#_u^SsUQg<}59< zTvH3%XS4G+6FF^(m6bVF&nSUIXcl;nw{=H$%fgeJ>CgDYiLdpDXr{;-AnG z8dvcrHYVMI&`R6;GWekI@Ir3!uo)oz4^{6q0m^}@f2tM9&=YHNi6-?rh0-{+k@cQm zdp`g#YdQn%MDVg2GR>wZ`n2<0l4)9nx1Wfr&!Dvz=bPwU!h2S?ez6MVc5APE4-xLB zi&W9Q8k2@0w!C53g?iAIQ}~p*3O(@zja6KQ=M3zfW*_6o5SwR-)6VBh~m7{^-=MC-owYH5-u40a}a0liho3QZZ5L{bS_xM1)4}19)zTU$$MY zq3eZML1WC{K%YFd`Be0M-rkO^l?h{kM{$2oK1*A@HVJ57*yhDkUF!2WZ&oA4Y-sK( zCY69%#`mBCi6>6uw(x4gbFaP0+FD*JKJ-q!F1E?vLJ+d35!I5d7@^eU?(CS|C^tmI5?lv@s{{*|1F zFg|OzNpZ0hxljdjaW%45O0MOttRrd(Z?h{HYbB-KFUx&9GfFL3b8NwZ$zNu)WbBD` zYkj$^UB5%3Pj1MDr>S2Ejr9pUcgA!;ZG!@{uAy12)vG=*^9-|dNQBc8&`oxBlU~#y zs!anJX&T?57Jdr^sb>e+V`MVfY>Y0ESg7MG<7W0g&bR-ZYzzZ%2H&Etcp zcd6QeXO1D!5A#zM0lx*GH}`M)2~ZFLE;sP^RSB5wVMNfiZXPd(cmO>j=OSA3`o5r& zna(|^jGXbdN7PK)U8b7^zYtYkkeb%<%F~=OqB~kXMQkq}ii|skh@WSRt>5za;cjP0 zZ~nD%6)wzedqE}BMLt~qKwlvTr33))#uP~xyw#*Eaa|DbMQ_%mG0U8numf8)0DX`r zRoG2bM;#g|p-8gWnwRV5SCW0tLjLO&9Z?K>FImeIxlGUgo0Zk`9Qzhj1eco~7XZy+hXc@YF&ZQ=? zn*^1O56yK^x{y}q`j7}blGCx%dydV!c7)g~tJzmHhV=W~jbWRRR{1<^oDK+1clprm zz$eCy7y9+?{E|YgkW~}}iB#I4XoJ*xr8R?i_Hv$=Cof5bo-Nj~f`-DLebH}&0% zfQj9@WGd4;N~Y?mzQsHJTJq6!Qzl^-vwol(+fMt#Pl=Wh#lI5Vmu@QM0=_r+1wHt` z+8WZ~c2}KQQ+q)~2Ki77QvV&`xb|xVcTms99&cD$Zz4+-^R4kvUBxG8gDk7Y`K*)JZ^2rL(+ZWV~%W(@6 z)0bPArG#BROa_PHs~&WplQ_UIrpd)1N1QGPfv!J(Z9jNT#i%H?CE6|pPZb9hJ1JW4 z^q;ft#!HRNV0YgPojzIYT`8LuET2rUe-J|c!9l4`^*;4WtY@Ew@pL>wkjmMgGfN7 ze}}GtmU0@<_#08~I-Suk=^*9GLW=H4xhsml;vAV{%hy5Eegl@!6qKqbG024%n2HHw zCc@ivW_$@5ZoHP70(7D+(`PvgjW1Pd`wsiuv-aCukMrafwDm)B!xXVy*j2opohhoU zcJz%ADmj>i3`-3-$7nQKBQQuGY;2Qt&+(L~C>vSGFj5{Mlv?T_^dql;{zkpe4R1}R z%XfZyQ}wr*sr>jrKgm*PWLjuVc%6&&`Kbf1SuFpHPN&>W)$GmqC;pIoBC`=4-hPY8 zT*>%I2fP}vGW;R=^!1be?ta2UQd2>alOFFbVl;(SQJ4Jk#)4Z0^wpWEVvY4=vyDk@ zqlModi@iVPMC+{?rm=4(n+<;|lmUO@UKYA>EPTS~AndtK^Wy^%#3<;(dQdk3WaUkRtzSMC9}7x2||CNpF#(3T4C)@ z$~RWs`BNABKX|{cmBt>Q=&gkXl&x!!NK_%5hW0LS)Z4PB>%sV?F-{Wyj#s7W%$F{D zXdK^Fp3wvy+48+GP6F_|^PCRx=ddcTO3sG;B23A49~Qaw31SZ0Rc~`r4qqt%#OGW{ zCA_(LG5^N>yzUn&kAgVmxb=EA8s&tBXC}S1CZ(KoW)(%^JjLTPo^fs`Va;`=YlVPgmB$!yB}<(4ym6OeZ3xAJJ#;)2+B%p3P1Wt+d$eo`vz`T zXfUP2))kBDPoscH;Jc7I3NU<({|@wM$&GaDt`n7WLgIY3IA7A6-_R?z8N3mz|}*i z(zl5ot--Oq@f2-nv{X(ujT2T(k1vY_qh93pK@>H-qc%2Xta)IP0Q%zt%bqYgI`o!wv!0QerB`nCN^1n|@$sVOQ!V0teVG!I z_fD%JvfDeT1cK#-{o6Gv7}& zY0#NWin~kVaf$aufV&;63Hbs|`QVZWpDX6IMk1Hj2G}fiH9e-^6u2zf^FIr^BwD<6zjw63+{yUe8PUFvk8v{sJ=R{d#`O!sz`Q13~< zPT$JS(w=yQfU2`zPCNfSw=&zup@DXc(98afjhv@1w_f!m2Z>rMJ19AB&dB%P#Ls3b z=lK7OILM+SQ&VEd=1GN6o&>YVVtIzoZ%=Z_SdqJN2}E43{bE`>w+A;=y->@^k{oCC z$F*WTY&?34;kfyFV?b*Xb1Pq`Z=%OgwEg)Rz)tx=`f%5#w_INP=x&z5!jI;#;N$ma zhO)+MDm;SxOEVL15; zGq(v2pL3&P1Sl)8P*;G-fd{l1QJsv@e@d8)1PK4w2m*M%V3j-V~L^$i|&C@b?D?9tfwE{B^}Z$k8e5FmQ>v7Xz)sG32g9t}YBt zyR$+*_00RmPx+0mW+vVG4mxd(n$(eQf3-w>JPl2UJpafrPaL5@2j}%{VE-) zBI%6Qpj*dsdH<;g!S!avA~bv^0E+ zfyJbSjPb+j;J52U)<|cIcntQBI2T#>2;tOxu{%D?kML476AErF(qN9hPva5Nkc@BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y@5qwPB{BRkWACf-P(P$&~4qam*WHydX{n+IbmGYb==K@%$n zLLuXVCYGNpO)OtGI@GYRl%y7yY~Ih3$TXTZhA0d&(jTNY*} z77qhACPjve66(|BHa1W8(b{lLZ0DvsjZ;s$D?R63_%1{_eUJVEU7(Vi+=-`tE&Ol# egQZ(gq#*6QwRP@-`O9n<3dEJM^}lTGT?GJP=28~` delta 240 zcmaDO^-9XYpouq)jZ>@5qwPB{BRkWACf;zMP%slCqam*WHydX{n+IbmGYb==K@%%G zLLuXVCYB#8O)OtFI@GW*SCkZQKERU6&gy8;#ArKNk7sqgk)e^HnSrsPxq(HLfj(R# zCySvHivruKO$Hr@@Z@^4JBQ=4M) - -
- - {{ $t('strings.hello') }} {{ title }} - - -
diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/i18n/en-US.json b/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/i18n/en-US.json deleted file mode 100644 index 3cb24b374..000000000 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/i18n/en-US.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "strings": { - "hello": "Hello", - "world": "World" - }, - "Files": { - } -} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/i18n/zh-CN.json b/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/i18n/zh-CN.json deleted file mode 100644 index c804e32c0..000000000 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/i18n/zh-CN.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "strings": { - "hello": "您好", - "world": "世界" - }, - "Files": { - } -} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.css b/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.css deleted file mode 100644 index 2b45eb97c..000000000 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.css +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -.container { - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - left: 0px; - top: 0px; - width: 100%; - height: 100%; -} - -.title { - font-size: 60px; - text-align: center; - width: 100%; - height: 40%; - margin: 10px; -} -.btn { - width: 50%; - height: 100px; - font-size: 40px; -} - -@media screen and (device-type: phone) and (orientation: landscape) { - .title { - font-size: 60px; - } -} - -@media screen and (device-type: tablet) and (orientation: landscape) { - .title { - font-size: 100px; - } -} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.hml b/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.hml deleted file mode 100644 index 61ea59d93..000000000 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestAbility/pages/index/index.hml +++ /dev/null @@ -1,21 +0,0 @@ - - -
- - {{ $t('strings.hello') }} {{title}} - - -
diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestRunner/OpenHarmonyTestRunner.js deleted file mode 100644 index 05ba57825..000000000 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/TestRunner/OpenHarmonyTestRunner.js +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' - -function translateParamsToString(parameters) { - const keySet = new Set([ - '-s class', '-s notClass', '-s suite', '-s itName', - '-s level', '-s testType', '-s size', '-s timeout', - '-s package', '-s dryRun' - ]) - let targetParams = ''; - for (const key in parameters) { - if (keySet.has(key)) { - targetParams += ' ' + key + ' ' + parameters[key] - } - } - return targetParams.trim() -} - - export default { - onPrepare() { - console.info('OpenHarmonyTestRunner OnPrepare') - }, - onRun() { - console.log('OpenHarmonyTestRunner onRun run') - var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - - var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.MainAbility' - - var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName - cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) - var debug = abilityDelegatorArguments.parameters["-D"] - console.info('debug value : '+debug) - if (debug == 'true') - { - cmd += ' -D' - } - console.info('cmd : '+cmd) - abilityDelegator.executeShellCommand(cmd, (err, data) => { - console.info('executeShellCommand : err : ' + JSON.stringify(err)); - console.info('executeShellCommand : data : ' + data.stdResult); - console.info('executeShellCommand : data : ' + data.exitCode); - }) - } -}; diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/test/List.test.js b/commonlibrary/ets_utils/worker_lib_standard/src/main/js/test/List.test.js deleted file mode 100644 index 6385576c5..000000000 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/js/test/List.test.js +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 workerTest from './Worker.test.js' -import threadWorkerTest from './ThreadWorker.test.js' - -export default function testsuite() { - workerTest() - threadWorkerTest() -} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/src/main/resources/base/element/string.json b/commonlibrary/ets_utils/worker_lib_standard/src/main/resources/base/element/string.json deleted file mode 100644 index 8ffbe6522..000000000 --- a/commonlibrary/ets_utils/worker_lib_standard/src/main/resources/base/element/string.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "entry_MainAbility" - }, - { - "name": "mainability_description", - "value": "JS_Empty Ability" - }, - { - "name": "MainAbility_desc", - "value": "description" - }, - { - "name": "MainAbility_label", - "value": "label" - }, - { - "name": "TestAbility_desc", - "value": "description" - }, - { - "name": "TestAbility_label", - "value": "label" - } - ] -} \ No newline at end of file -- GitLab