diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/AppScope/app.json b/commonlibrary/ets_utils/taskpool_lib_standard/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..1eea79638876947d7dc5e15832820c7eec376d0f --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "com.example.taskpool", + "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/taskpool_lib_standard/AppScope/resources/base/element/string.json b/commonlibrary/ets_utils/taskpool_lib_standard/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f0fd8879739111f872d28df80ba95d0c9c540a11 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"app_name", + "value":"TaskPoolTest" + } + ] +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/resources/base/media/icon.png b/commonlibrary/ets_utils/taskpool_lib_standard/AppScope/resources/base/media/app_icon.png similarity index 100% rename from commonlibrary/ets_utils/taskpool_lib_standard/src/main/resources/base/media/icon.png rename to commonlibrary/ets_utils/taskpool_lib_standard/AppScope/resources/base/media/app_icon.png diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/BUILD.gn b/commonlibrary/ets_utils/taskpool_lib_standard/BUILD.gn index aeace9fd10d0e73338102d792e37f8ebfefa215b..903f94edf0cefc8126a4d03120cb1b3ffeb4a4bc 100644 --- a/commonlibrary/ets_utils/taskpool_lib_standard/BUILD.gn +++ b/commonlibrary/ets_utils/taskpool_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 @@ -12,27 +12,32 @@ # limitations under the License. import("//test/xts/tools/build/suite.gni") + ohos_js_hap_suite("taskPool_js_test") { - hap_profile = "./src/main/config.json" - js2abc = true + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" deps = [ - ":taskPool_js_assets", - ":taskPool_resources", + ":taskpool_js_assets", + ":taskpool_resources", ] - - certificate_profile = "./signature/openharmony_sx.p7b" + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" hap_name = "ActsTaskPoolJSApiTest" - subsystem_name = "commonlibrary" part_name = "ets_utils" } -ohos_js_assets("taskPool_js_assets") { - js2abc = true - hap_profile = "./src/main/config.json" - source_dir = "./src/main/js" +ohos_app_scope("taskpool_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] } -ohos_resources("taskPool_resources") { - sources = [ "./src/main/resources" ] - hap_profile = "./src/main/config.json" + +ohos_js_assets("taskpool_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("taskpool_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":taskpool_app_profile" ] + hap_profile = "entry/src/main/module.json" } diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/Test.json b/commonlibrary/ets_utils/taskpool_lib_standard/Test.json index 4359811e8a62e67fa32f0d1f17de272ef61a37f3..5006b564e3941591b82ff5ed52320b1bddb6c9fa 100644 --- a/commonlibrary/ets_utils/taskpool_lib_standard/Test.json +++ b/commonlibrary/ets_utils/taskpool_lib_standard/Test.json @@ -3,9 +3,9 @@ "driver": { "type": "OHJSUnitTest", "test-timeout": "800000", - "shell-timeout": "800000", "bundle-name": "com.example.taskpool", - "package-name": "com.example.taskpool" + "module-name": "entry", + "shell-timeout": "800000" }, "kits": [ { @@ -15,5 +15,5 @@ "type": "AppInstallKit", "cleanup-apps": true } - ] -} \ No newline at end of file + ] +} diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/app.js b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/Application/AbilityStage.ts similarity index 54% rename from commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/app.js rename to commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/Application/AbilityStage.ts index ff2c11965e08dd2df603562158980963c00e7a25..19e6e2af15a1b22500cf9cdb7d7f08b59f26674d 100644 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/app.js +++ b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/Application/AbilityStage.ts @@ -1,22 +1,22 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); + * 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, + * 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 { +import AbilityStage from "@ohos.app.ability.AbilityStage" + +var printLog0 = 'TaskPool:AbilityStage:' +export default class MyAbilityStage extends AbilityStage { onCreate() { - console.info('AceApplication onCreate'); - }, - onDestroy() { - console.info('AceApplication onDestroy'); + console.info(printLog0 + "onCreate") } -}; +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/MainAbility/MainAbility.ts b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..cc8dfedc729e0272902fbe76bc69b772e720d81e --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_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 = 'TaskPool: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/taskpool_lib_standard/src/main/js/TestAbility/app.js b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/MainAbility/pages/index.ets similarity index 53% rename from commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/app.js rename to commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/MainAbility/pages/index.ets index e4d30d4ed362459e8ae4e3e1f5e697e73c96d124..73e1a053ca8b51ee9da71676b613c5f08d9d5445 100644 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/app.js +++ b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/MainAbility/pages/index.ets @@ -1,31 +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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import { Hypium } from '@ohos/hypium' -import testsuite from '../test/List.test' - -export default { - onCreate() { - console.info('TestApplication onCreate'); - var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); - console.info('start run testcase!!!'); - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); - }, - 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 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 TaskPool' + + 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/taskpool_lib_standard/entry/src/main/ets/TestAbility/TestAbility.ts b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..36c9cf9784551a8651d0e62081df36744a0f1574 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_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/taskpool_lib_standard/entry/src/main/ets/TestAbility/pages/index.ets b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_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/taskpool_lib_standard/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..9b0a9f8438dd26dbe2bb5cad56af74be8c3f4048 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_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.taskpool.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/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.js b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/List.test.js similarity index 80% rename from commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.js rename to commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/List.test.js index 88b083a7f6b979019d6a2c5ad20b19c5fd43286b..27875f218f487ebf2f058481d63e1d684ab9a440 100644 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.js +++ b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/List.test.js @@ -1,26 +1,20 @@ -/* - * 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 TaskPoolTest from './TaskPool.test.js' + +export default function List() { + TaskPoolTest() +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/test/TaskPool.test.js b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js similarity index 96% rename from commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/test/TaskPool.test.js rename to commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js index 9ab6e04d55fd3b448769990931190977305131ae..9578d01bcbb229e0299607cbab5587ec81003b5a 100644 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/test/TaskPool.test.js +++ b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js @@ -1,1483 +1,1483 @@ -/* - * 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' -import taskpool from '@ohos.taskpool' -export default function TaskPoolTest() { -describe('ActsAbilityTest', function () { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - - function promiseCase() { - let p = new Promise(function (resolve, reject) { - setTimeout(function () { - resolve() - }, 100) - }).then(undefined, (error) => { - }) - return p - } - - it('TaskPoolTestClass001', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result = await taskpool.execute(Sum, 10, 20); - expect(result).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass002', 0, async function (done) { - function Add(value1, value2) { - "use concurrent" - if (value1 & value2) - return true; - else - return false; - } - var result = await taskpool.execute(Add, true, true); - expect(result).assertEqual(true); - done(); - }) - - it('TaskPoolTestClass003', 0, async function (done) { - function StrCat(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result = await taskpool.execute(StrCat, "abc", "def"); - expect(result).assertEqual("abcdef"); - done(); - }) - - it('TaskPoolTestClass004', 0, async function (done) { - function StrCat(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result = await taskpool.execute(StrCat, "abc", "def"); - result = await taskpool.execute(StrCat, "abc", "def"); - expect(result).assertEqual("abcdef"); - done(); - }) - - it('TaskPoolTestClass005', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - function StrCat(value1, value2) { - return value1 + value2; - } - return value1+StrCat(value2,"hello"); - } - var result = await taskpool.execute(Sum, "abc", "def"); - expect(result).assertEqual("abcdefhello"); - done(); - }) - - it('TaskPoolTestClass006', 0, async function (done) { - function Sum(arg1, arg2) { - "use concurrent" - let value = []; - value[0] = arg1[0] + arg2[0]; - value[1] = arg1[1] + arg2[1]; - return value; - } - var result = await taskpool.execute(Sum, [1,2], [3,4]); - expect(result[0]).assertEqual(4); - expect(result[1]).assertEqual(6); - done(); - }) - - it('TaskPoolTestClass007', 0, async function (done) { - function Sum(arg1, arg2) { - "use concurrent" - let value = arg1; - value.a = arg1.a + arg2.a; - value.b = arg1.b + arg2.b; - return value; - } - var result = await taskpool.execute(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}); - expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}"); - done(); - }) - - it('TaskPoolTestClass008', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result = await taskpool.execute(Sum, 10); - expect(result.toString()).assertEqual("NaN"); - done(); - }) - - it('TaskPoolTestClass009', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result = await taskpool.execute(Sum, 10, 20, 30); - expect(result).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass010', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result1 = await taskpool.execute(Sum, 10, 20); - var result2 = await taskpool.execute(Sum, 30, 40); - expect(result1).assertEqual(30); - expect(result2).assertEqual(70); - done(); - }) - - it('TaskPoolTestClass011', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result1 = await taskpool.execute(Sum, 10, 20); - var result2 = await taskpool.execute(Sum, 10, 20); - expect(result1).assertEqual(30); - expect(result2).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass012', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - function Multi(value1, value2) { - "use concurrent" - return value1 * value2; - } - var result1 = await taskpool.execute(Sum, 10, 20); - var result2 = await taskpool.execute(Multi, 10, 20); - var result3 = await taskpool.execute(Sum, 10, 30); - var result4 = await taskpool.execute(Multi, 20, 20); - expect(result1).assertEqual(30); - expect(result2).assertEqual(200); - expect(result3).assertEqual(40); - expect(result4).assertEqual(400); - done(); - }) - - it('TaskPoolTestClass013', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task = new taskpool.Task(Sum, 10, 20); - var result = await taskpool.execute(task); - expect(result).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass014', 0, async function (done) { - function Add(value1, value2) { - "use concurrent" - if (value1 & value2) - return true; - else - return false; - } - var task = new taskpool.Task(Add, true, true); - var result = await taskpool.execute(task); - expect(result).assertEqual(true); - done(); - }) - - it('TaskPoolTestClass015', 0, async function (done) { - function StrCat(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task = new taskpool.Task(StrCat, "abc", "def"); - var result = await taskpool.execute(task); - expect(result).assertEqual("abcdef"); - done(); - }) - - it('TaskPoolTestClass016', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - function StrCat(value1, value2) { - return value1 + value2; - } - return value1+StrCat(value2,"hello"); - } - var task = new taskpool.Task(Sum, "abc", "def"); - var result = await taskpool.execute(task); - expect(result).assertEqual("abcdefhello"); - done(); - }) - - it('TaskPoolTestClass017', 0, async function (done) { - function Sum(arg1, arg2) { - "use concurrent" - let value = []; - value[0] = arg1[0] + arg2[0]; - value[1] = arg1[1] + arg2[1]; - return value; - } - var task = new taskpool.Task(Sum, [1,2], [3,4]); - var result = await taskpool.execute(task); - expect(result[0]).assertEqual(4); - expect(result[1]).assertEqual(6); - done(); - }) - - it('TaskPoolTestClass018', 0, async function (done) { - function Sum(arg1, arg2) { - "use concurrent" - let value = arg1; - value.a = arg1.a + arg2.a; - value.b = arg1.b + arg2.b; - return value; - } - var task = new taskpool.Task(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}); - var result = await taskpool.execute(task); - expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}"); - done(); - }) - - it('TaskPoolTestClass019', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task = new taskpool.Task(Sum, 10); - var result = await taskpool.execute(task); - expect(result.toString()).assertEqual("NaN"); - done(); - }) - - it('TaskPoolTestClass020', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task = new taskpool.Task(Sum, 10, 20, 30); - var result = await taskpool.execute(task); - expect(result).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass021', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task = new taskpool.Task(Sum, 10, 20); - var result1 = await taskpool.execute(task); - var result2 = await taskpool.execute(task); - expect(result1).assertEqual(30); - expect(result2).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass022', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task1 = new taskpool.Task(Sum, 10, 20); - var task2 = new taskpool.Task(Sum, 30, 40); - var result1 = await taskpool.execute(task1); - var result2 = await taskpool.execute(task2); - expect(result1).assertEqual(30); - expect(result2).assertEqual(70); - done(); - }) - - it('TaskPoolTestClass023', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task1 = new taskpool.Task(Sum, 10, 20); - var task2 = new taskpool.Task(Sum, 10, 20); - var result1 = await taskpool.execute(task1); - var result2 = await taskpool.execute(task2); - expect(result1).assertEqual(30); - expect(result2).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass024', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - function Multi(value1, value2) { - "use concurrent" - return value1 * value2; - } - var task1 = new taskpool.Task(Sum, 10, 20); - var result1 = await taskpool.execute(task1); - var task2 = new taskpool.Task(Multi, 10, 20); - var result2 = await taskpool.execute(task2); - var task3 = new taskpool.Task(Sum, 10, 30); - var result3 = await taskpool.execute(task3); - var task4 = new taskpool.Task(Multi, 20, 20); - var result4 = await taskpool.execute(task4); - expect(result1).assertEqual(30); - expect(result2).assertEqual(200); - expect(result3).assertEqual(40); - expect(result4).assertEqual(400); - done(); - }) - - it('TaskPoolTestClass025', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result; - var isTerminate = false; - var task = new taskpool.Task(Sum, 10, 20) - taskpool.execute(task).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass026', 0, async function (done) { - function Add(value1, value2) { - "use concurrent" - if (value1 & value2) - return true; - else - return false; - } - var task = new taskpool.Task(Add, true, true) - var result; - var isTerminate = false; - taskpool.execute(task).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result).assertEqual(true); - done(); - }) - - it('TaskPoolTestClass027', 0, async function (done) { - function StrCat(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task = new taskpool.Task(StrCat, "abc", "def") - var result; - var isTerminate = false; - taskpool.execute(task).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result).assertEqual("abcdef"); - done(); - }) - - it('TaskPoolTestClass028', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - function StrCat(value1, value2) { - return value1 + value2; - } - return value1+StrCat(value2,"hello"); - } - var task = new taskpool.Task(Sum, "abc", "def"); - var result; - var isTerminate = false; - taskpool.execute(task).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result).assertEqual("abcdefhello"); - done(); - }) - - it('TaskPoolTestClass029', 0, async function (done) { - function Sum(arg1, arg2) { - "use concurrent" - let value = []; - value[0] = arg1[0] + arg2[0]; - value[1] = arg1[1] + arg2[1]; - return value; - } - var task = new taskpool.Task(Sum, [1,2], [3,4]); - var result; - var isTerminate = false; - taskpool.execute(task).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result[0]).assertEqual(4); - expect(result[1]).assertEqual(6); - done(); - }) - - it('TaskPoolTestClass030', 0, async function (done) { - function Sum(arg1, arg2) { - "use concurrent" - let value = arg1; - value.a = arg1.a + arg2.a; - value.b = arg1.b + arg2.b; - return value; - } - var task = new taskpool.Task(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}); - var result; - var isTerminate = false; - taskpool.execute(task).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}"); - done(); - }) - - it('TaskPoolTestClass031', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task = new taskpool.Task(Sum, 10); - var result; - var isTerminate = false; - taskpool.execute(task).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result.toString()).assertEqual("NaN"); - done(); - }) - - it('TaskPoolTestClass032', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task = new taskpool.Task(Sum, 10, 20, 30); - var result; - var isTerminate = false; - taskpool.execute(task).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass033', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result1; - var result2; - var isTerminate1 = false; - var isTerminate2 = false; - - var task1 = new taskpool.Task(Sum, 10, 20); - taskpool.execute(task1).then((ret1) => { - result1 = ret1; - isTerminate1 = true; - }) - - var task2 = new taskpool.Task(Sum, 30, 40); - taskpool.execute(task2).then((ret2) => { - result2 = ret2; - isTerminate2 = true; - }) - while (!isTerminate1 || !isTerminate2) { - await promiseCase() - } - expect(result1).assertEqual(30); - expect(result2).assertEqual(70); - done(); - }) - - it('TaskPoolTestClass034', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result1; - var result2; - var isTerminate1 = false; - var isTerminate2 = false; - - var task1 = new taskpool.Task(Sum, 10, 20) - taskpool.execute(task1).then((ret1) => { - result1 = ret1; - isTerminate1 = true; - }) - var task2 = new taskpool.Task(Sum, 10, 20) - taskpool.execute(task2).then((ret2) => { - result2 = ret2; - isTerminate2 = true; - }) - while (!isTerminate1 || !isTerminate2) { - await promiseCase() - } - expect(result1).assertEqual(30); - expect(result2).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass035', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result1; - var result2; - var isTerminate1 = false; - var isTerminate2 = false; - - var task = new taskpool.Task(Sum, 10, 20) - taskpool.execute(task).then((ret1) => { - result1 = ret1; - isTerminate1 = true; - }) - taskpool.execute(task).then((ret2) => { - result2 = ret2; - isTerminate2 = true; - }) - while (!isTerminate1 || !isTerminate2) { - await promiseCase() - } - expect(result1).assertEqual(30); - expect(result2).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass036', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - function Multi(value1, value2) { - "use concurrent" - return value1 * value2; - } - - var result1; - var result2; - var result3; - var result4; - var isTerminate1 = false; - var isTerminate2 = false; - var isTerminate3 = false; - var isTerminate4 = false; - - var task1 = new taskpool.Task(Sum, 10, 20) - taskpool.execute(task1).then((ret1) => { - result1 = ret1; - isTerminate1 = true; - }) - var task2 = new taskpool.Task(Multi, 10, 20) - taskpool.execute(task2).then((ret2) => { - result2 = ret2; - isTerminate2 = true; - }) - var task3 = new taskpool.Task(Sum, 10, 30) - taskpool.execute(task3).then((ret3) => { - result3 = ret3; - isTerminate3 = true; - }) - var task4 = new taskpool.Task(Multi, 20, 20) - taskpool.execute(task4).then((ret4) => { - result4 = ret4; - isTerminate4 = true; - }) - - while (!isTerminate1 || !isTerminate2 || !isTerminate3 || !isTerminate4) { - await promiseCase() - } - expect(result1).assertEqual(30); - expect(result2).assertEqual(200); - expect(result3).assertEqual(40); - expect(result4).assertEqual(400); - done(); - }) - - it('TaskPoolTestClass037', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result; - var isTerminate = false; - taskpool.execute(Sum, 10, 20).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass038', 0, async function (done) { - function Add(value1, value2) { - "use concurrent" - if (value1 & value2) - return true; - else - return false; - } - var result; - var isTerminate = false; - taskpool.execute(Add, true, false).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result).assertEqual(false); - done(); - }) - - it('TaskPoolTestClass039', 0, async function (done) { - function StrCat(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result; - var isTerminate = false; - taskpool.execute(StrCat, "abc", "def").then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result).assertEqual("abcdef"); - done(); - }) - - it('TaskPoolTestClass040', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - function StrCat(value1, value2) { - return value1 + value2; - } - return value1+StrCat(value2,"hello"); - } - var result; - var isTerminate = false; - taskpool.execute(Sum, "abc", "def").then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result).assertEqual("abcdefhello"); - done(); - }) - - it('TaskPoolTestClass041', 0, async function (done) { - function Sum(arg1, arg2) { - "use concurrent" - let value = []; - value[0] = arg1[0] + arg2[0]; - value[1] = arg1[1] + arg2[1]; - return value; - } - var result; - var isTerminate = false; - taskpool.execute(Sum, [1,2], [3,4]).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result[0]).assertEqual(4); - expect(result[1]).assertEqual(6); - done(); - }) - - it('TaskPoolTestClass042', 0, async function (done) { - function Sum(arg1, arg2) { - "use concurrent" - let value = arg1; - value.a = arg1.a + arg2.a; - value.b = arg1.b + arg2.b; - return value; - } - var result; - var isTerminate = false; - taskpool.execute(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}"); - done(); - }) - - it('TaskPoolTestClass043', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result; - var isTerminate = false; - taskpool.execute(Sum, 10).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result.toString()).assertEqual("NaN"); - done(); - }) - - it('TaskPoolTestClass044', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result; - var isTerminate = false; - taskpool.execute(Sum, 10, 20, 30).then((ret) => { - result = ret; - isTerminate = true; - }) - while (!isTerminate) { - await promiseCase() - } - expect(result).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass045', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result1; - var result2; - var isTerminate1 = false; - var isTerminate2 = false; - - taskpool.execute(Sum, 10, 20).then((ret1) => { - result1 = ret1; - isTerminate1 = true; - }) - taskpool.execute(Sum, 30, 40).then((ret2) => { - result2 = ret2; - isTerminate2 = true; - }) - while (!isTerminate1 || !isTerminate2) { - await promiseCase() - } - expect(result1).assertEqual(30); - expect(result2).assertEqual(70); - done(); - }) - - it('TaskPoolTestClass046', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var result1; - var result2; - var isTerminate1 = false; - var isTerminate2 = false; - - taskpool.execute(Sum, 10, 20).then((ret1) => { - result1 = ret1; - isTerminate1 = true; - }) - taskpool.execute(Sum, 10, 20).then((ret2) => { - result2 = ret2; - isTerminate2 = true; - }) - while (!isTerminate1 || !isTerminate2) { - await promiseCase() - } - expect(result1).assertEqual(30); - expect(result2).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass047', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - function Multi(value1, value2) { - "use concurrent" - return value1 * value2; - } - - var result1; - var result2; - var result3; - var result4; - var isTerminate1 = false; - var isTerminate2 = false; - var isTerminate3 = false; - var isTerminate4 = false; - - taskpool.execute(Sum, 10, 20).then((ret1) => { - result1 = ret1; - isTerminate1 = true; - }) - taskpool.execute(Multi, 10, 20).then((ret2) => { - result2 = ret2; - isTerminate2 = true; - }) - taskpool.execute(Sum, 10, 30).then((ret3) => { - result3 = ret3; - isTerminate3 = true; - }) - taskpool.execute(Multi, 20, 20).then((ret4) => { - result4 = ret4; - isTerminate4 = true; - }) - while (!isTerminate1 || !isTerminate2 || !isTerminate3 || !isTerminate4) { - await promiseCase() - } - expect(result1).assertEqual(30); - expect(result2).assertEqual(200); - expect(result3).assertEqual(40); - expect(result4).assertEqual(400); - done(); - }) - - it('TaskPoolTestClass048', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - try { - var result = await taskpool.execute(Sum); - } catch(e) { - expect(e.toString()).assertEqual("BusinessError: taskpool:: first param must be object when argc is one"); - } - done(); - }) - - it('TaskPoolTestClass061', 0, async function (done) { - function Sum(value1, value2) { - "use concurrent" - return value1 + value2; - } - var task1 = new taskpool.Task(Sum, 10, 20); - var task2 = new taskpool.Task(Sum, 30, 40); - var task3 = new taskpool.Task(Sum, 50, 60); - var result1 = await taskpool.execute(task1,taskpool.Priority.LOW); - var result2 = await taskpool.execute(task2,taskpool.Priority.HIGH); - var result3 = await taskpool.execute(task3,taskpool.Priority.MEDIUM); - expect(result1).assertEqual(30); - expect(result2).assertEqual(70); - expect(result3).assertEqual(110); - done(); - }) - - it('TaskPoolTestClass062', 0, async function (done) { - async function func(value1, value2) { - "use concurrent" - let result = await new Promise((resolve, reject) => { - let value = value1 + value2; - resolve(value); - }) - return result; - } - var result = await taskpool.execute(func, 10, 20); - expect(result).assertEqual(30); - done(); - }) - - it('TaskPoolTestClass063', 0, async function (done) { - async function func(value1, value2) { - "use concurrent" - let result = await new Promise((resolve, reject) => { - let value = value1 + value2; - resolve(value); - }) - return result; - } - var task = new taskpool.Task(func, 10, 20); - var result = await taskpool.execute(task); - expect(result).assertEqual(30); - done(); - }) - - /** - * @tc.number : TaskPoolTestClass049 - * @tc.name : Async Function Cancel task - * @tc.desc : Cancel tasks that have not been executed - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass049', 0, async function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - function additionDelay(arg) { - "use concurrent" - var start = new Date().getTime(); - while (new Date().getTime() - start < 200) { - continue; - } - return arg + 1; - } - try { - var task1 = new taskpool.Task(additionDelay, 100); - var task2 = new taskpool.Task(additionDelay, 200); - var task3 = new taskpool.Task(additionDelay, 200); - var task4 = new taskpool.Task(additionDelay, 200); - var task5 = new taskpool.Task(additionDelay, 200); - var task6 = new taskpool.Task(additionDelay, 200); - var task7 = new taskpool.Task(additionDelay, 200); - var task8 = new taskpool.Task(additionDelay, 200); - var task9 = new taskpool.Task(additionDelay, 200); - var task10 = new taskpool.Task(additionDelay, 200); - var task11 = new taskpool.Task(addition, 300); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - var result3 = taskpool.execute(task3); - var result4 = taskpool.execute(task4); - var result5 = taskpool.execute(task5); - var result6 = taskpool.execute(task6); - var result7 = taskpool.execute(task7); - var result8 = taskpool.execute(task8); - var result9 = taskpool.execute(task9); - var result10 = taskpool.execute(task10); - var result11 = taskpool.execute(task11); - - var start = new Date().getTime(); - while (new Date().getTime() - start < 20) { - continue; - } - - taskpool.cancel(task11); - } - catch (e) { - expect(e.toString()).assertEqual(""); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass050 - * @tc.name : Sync Function Cancel task - * @tc.desc : Cancel tasks that have not been executed - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass050', 0, function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - function additionDelay(arg) { - "use concurrent" - var start = new Date().getTime(); - while (new Date().getTime() - start < 200) { - continue; - } - return arg + 1; - } - try { - var task1 = new taskpool.Task(additionDelay, 100); - var task2 = new taskpool.Task(additionDelay, 200); - var task3 = new taskpool.Task(additionDelay, 200); - var task4 = new taskpool.Task(additionDelay, 200); - var task5 = new taskpool.Task(additionDelay, 200); - var task6 = new taskpool.Task(additionDelay, 200); - var task7 = new taskpool.Task(additionDelay, 200); - var task8 = new taskpool.Task(additionDelay, 200); - var task9 = new taskpool.Task(additionDelay, 200); - var task10 = new taskpool.Task(additionDelay, 200); - var task11 = new taskpool.Task(addition, 300); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - var result3 = taskpool.execute(task3); - var result4 = taskpool.execute(task4); - var result5 = taskpool.execute(task5); - var result6 = taskpool.execute(task6); - var result7 = taskpool.execute(task7); - var result8 = taskpool.execute(task8); - var result9 = taskpool.execute(task9); - var result10 = taskpool.execute(task10); - var result11 = taskpool.execute(task11); - - var start = new Date().getTime(); - while (new Date().getTime() - start < 20) { - continue; - } - - taskpool.cancel(task11); - } - catch (e) { - expect(e.toString()).assertEqual(""); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass051 - * @tc.name : Async Function Cancel task - * @tc.desc : Cancel the task in progress - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass051', 0, async function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - function additionDelay(arg) { - "use concurrent" - var start = new Date().getTime(); - while (new Date().getTime() - start < 3000) { - continue; - } - return arg + 1; - } - try { - var task1 = new taskpool.Task(additionDelay, 100); - var task2 = new taskpool.Task(additionDelay, 200); - var task3 = new taskpool.Task(addition, 300); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - var result3 = taskpool.execute(task3); - - var start = new Date().getTime(); - while (new Date().getTime() - start < 1000) { - continue; - } - - taskpool.cancel(task1); - } - catch (e) { - expect(e.toString()).assertEqual( - "BusinessError: The task is executing when it is canceled, taskpool:: can not cancel the running task"); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass052 - * @tc.name : Sync Function Cancel task - * @tc.desc : Cancel the task in progress - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass052', 0, function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - function additionDelay(arg) { - "use concurrent" - var start = new Date().getTime(); - while (new Date().getTime() - start < 3000) { - continue; - } - return arg + 1; - } - try { - var task1 = new taskpool.Task(additionDelay, 100); - var task2 = new taskpool.Task(additionDelay, 200); - var task3 = new taskpool.Task(addition, 300); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - var result3 = taskpool.execute(task3); - - var start = new Date().getTime(); - while (new Date().getTime() - start < 1000) { - continue; - } - - taskpool.cancel(task1); - } - catch (e) { - expect(e.toString()).assertEqual( - "BusinessError: The task is executing when it is canceled, taskpool:: can not cancel the running task"); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass053 - * @tc.name : Async Function Cancel task - * @tc.desc : Cancel the executed task - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass053', 0, async function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - try { - var task1 = new taskpool.Task(addition, 100); - var task2 = new taskpool.Task(addition, 200); - var task3 = new taskpool.Task(addition, 300); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - var result3 = taskpool.execute(task3); - - var start = new Date().getTime(); - while (new Date().getTime() - start < 1000) { - continue; - } - - taskpool.cancel(task1); - } - catch (e) { - expect(e.toString()).assertEqual( - "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass054 - * @tc.name : Sync Function Cancel task - * @tc.desc : Cancel the executed task - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass054', 0, function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - try { - var task1 = new taskpool.Task(addition, 100); - var task2 = new taskpool.Task(addition, 200); - var task3 = new taskpool.Task(addition, 300); - var task4 = new taskpool.Task(addition, 400); - var task5 = new taskpool.Task(addition, 500); - var task6 = new taskpool.Task(addition, 600); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - var result3 = taskpool.execute(task3); - var result4 = taskpool.execute(task4); - var result5 = taskpool.execute(task5); - var result6 = taskpool.execute(task6); - - var start = new Date().getTime(); - while (new Date().getTime() - start < 1000) { - continue; - } - - taskpool.cancel(task3); - } - catch (e) { - expect(e.toString()).assertEqual( - "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass055 - * @tc.name : Async Function Cancel task - * @tc.desc : Cancel nonexistent task - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass055', 0, async function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - try { - var task1 = new taskpool.Task(addition, 100); - var task2 = new taskpool.Task(addition, 200); - var task3 = new taskpool.Task(addition, 300); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - - taskpool.cancel(task3); - } - catch (e) { - expect(e.toString()).assertEqual( - "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass056 - * @tc.name : Sync Function Cancel task - * @tc.desc : Cancel nonexistent task - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass056', 0, function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - try { - var task1 = new taskpool.Task(addition, 100); - var task2 = new taskpool.Task(addition, 200); - var task3 = new taskpool.Task(addition, 300); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - - taskpool.cancel(task3); - } - catch (e) { - expect(e.toString()).assertEqual( - "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass057 - * @tc.name : Async Function Cancel task - * @tc.desc : Canceling unexecuted tasks multiple times - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass057', 0, async function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - function additionDelay(arg) { - "use concurrent" - var start = new Date().getTime(); - while (new Date().getTime() - start < 3000) { - continue; - } - return arg + 1; - } - try { - var task1 = new taskpool.Task(additionDelay, 100); - var task2 = new taskpool.Task(additionDelay, 200); - var task3 = new taskpool.Task(addition, 300); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - var result3 = taskpool.execute(task3); - - var start = new Date().getTime(); - while (new Date().getTime() - start < 1000) { - continue; - } - - taskpool.cancel(task3); - taskpool.cancel(task3); - } - catch (e) { - expect(e.toString()).assertEqual( - "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass058 - * @tc.name : Sync Function Cancel task - * @tc.desc : Canceling unexecuted tasks multiple times - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass058', 0, function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - function additionDelay(arg) { - "use concurrent" - var start = new Date().getTime(); - while (new Date().getTime() - start < 3000) { - continue; - } - return arg + 1; - } - try { - var task1 = new taskpool.Task(additionDelay, 100); - var task2 = new taskpool.Task(additionDelay, 200); - var task3 = new taskpool.Task(addition, 300); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - var result3 = taskpool.execute(task3); - - var start = new Date().getTime(); - while (new Date().getTime() - start < 1000) { - continue; - } - - taskpool.cancel(task3); - taskpool.cancel(task3); - } - catch (e) { - expect(e.toString()).assertEqual( - "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass059 - * @tc.name : Async Function Cancel task - * @tc.desc : Cancel all tasks in sequence - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass059', 0, async function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - try { - var task1 = new taskpool.Task(addition, 100); - var task2 = new taskpool.Task(addition, 200); - var task3 = new taskpool.Task(addition, 300); - var task4 = new taskpool.Task(addition, 400); - var task5 = new taskpool.Task(addition, 500); - var task6 = new taskpool.Task(addition, 600); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - var result3 = taskpool.execute(task3); - var result4 = taskpool.execute(task4); - var result5 = taskpool.execute(task5); - var result6 = taskpool.execute(task6); - - var start = new Date().getTime(); - while (new Date().getTime() - start < 100) { - continue; - } - - taskpool.cancel(task6); - taskpool.cancel(task5); - taskpool.cancel(task4); - taskpool.cancel(task3); - taskpool.cancel(task2); - } - catch (e) { - expect(e.toString()).assertEqual( - "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); - } - done(); - }) - - /** - * @tc.number : TaskPoolTestClass060 - * @tc.name : Sync Function Cancel task - * @tc.desc : Cancel all tasks in sequence - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('TaskPoolTestClass060', 0, function (done) { - function addition(arg) { - "use concurrent" - return arg + 1; - } - try { - var task1 = new taskpool.Task(addition, 100); - var task2 = new taskpool.Task(addition, 200); - var task3 = new taskpool.Task(addition, 300); - var task4 = new taskpool.Task(addition, 400); - var task5 = new taskpool.Task(addition, 500); - var task6 = new taskpool.Task(addition, 600); - - var result1 = taskpool.execute(task1); - var result2 = taskpool.execute(task2); - var result3 = taskpool.execute(task3); - var result4 = taskpool.execute(task4); - var result5 = taskpool.execute(task5); - var result6 = taskpool.execute(task6); - - var start = new Date().getTime(); - while (new Date().getTime() - start < 100) { - continue; - } - - taskpool.cancel(task6); - taskpool.cancel(task5); - taskpool.cancel(task4); - taskpool.cancel(task3); - taskpool.cancel(task2); - } - catch (e) { - expect(e.toString()).assertEqual( - "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); - } - 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import taskpool from '@ohos.taskpool' +export default function TaskPoolTest() { +describe('ActsAbilityTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + + function promiseCase() { + let p = new Promise(function (resolve, reject) { + setTimeout(function () { + resolve() + }, 100) + }).then(undefined, (error) => { + }) + return p + } + + it('TaskPoolTestClass001', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result = await taskpool.execute(Sum, 10, 20); + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass002', 0, async function (done) { + function Add(value1, value2) { + "use concurrent" + if (value1 & value2) + return true; + else + return false; + } + var result = await taskpool.execute(Add, true, true); + expect(result).assertEqual(true); + done(); + }) + + it('TaskPoolTestClass003', 0, async function (done) { + function StrCat(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result = await taskpool.execute(StrCat, "abc", "def"); + expect(result).assertEqual("abcdef"); + done(); + }) + + it('TaskPoolTestClass004', 0, async function (done) { + function StrCat(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result = await taskpool.execute(StrCat, "abc", "def"); + result = await taskpool.execute(StrCat, "abc", "def"); + expect(result).assertEqual("abcdef"); + done(); + }) + + it('TaskPoolTestClass005', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + function StrCat(value1, value2) { + return value1 + value2; + } + return value1+StrCat(value2,"hello"); + } + var result = await taskpool.execute(Sum, "abc", "def"); + expect(result).assertEqual("abcdefhello"); + done(); + }) + + it('TaskPoolTestClass006', 0, async function (done) { + function Sum(arg1, arg2) { + "use concurrent" + let value = []; + value[0] = arg1[0] + arg2[0]; + value[1] = arg1[1] + arg2[1]; + return value; + } + var result = await taskpool.execute(Sum, [1,2], [3,4]); + expect(result[0]).assertEqual(4); + expect(result[1]).assertEqual(6); + done(); + }) + + it('TaskPoolTestClass007', 0, async function (done) { + function Sum(arg1, arg2) { + "use concurrent" + let value = arg1; + value.a = arg1.a + arg2.a; + value.b = arg1.b + arg2.b; + return value; + } + var result = await taskpool.execute(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}); + expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}"); + done(); + }) + + it('TaskPoolTestClass008', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result = await taskpool.execute(Sum, 10); + expect(result.toString()).assertEqual("NaN"); + done(); + }) + + it('TaskPoolTestClass009', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result = await taskpool.execute(Sum, 10, 20, 30); + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass010', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result1 = await taskpool.execute(Sum, 10, 20); + var result2 = await taskpool.execute(Sum, 30, 40); + expect(result1).assertEqual(30); + expect(result2).assertEqual(70); + done(); + }) + + it('TaskPoolTestClass011', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result1 = await taskpool.execute(Sum, 10, 20); + var result2 = await taskpool.execute(Sum, 10, 20); + expect(result1).assertEqual(30); + expect(result2).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass012', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + function Multi(value1, value2) { + "use concurrent" + return value1 * value2; + } + var result1 = await taskpool.execute(Sum, 10, 20); + var result2 = await taskpool.execute(Multi, 10, 20); + var result3 = await taskpool.execute(Sum, 10, 30); + var result4 = await taskpool.execute(Multi, 20, 20); + expect(result1).assertEqual(30); + expect(result2).assertEqual(200); + expect(result3).assertEqual(40); + expect(result4).assertEqual(400); + done(); + }) + + it('TaskPoolTestClass013', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task = new taskpool.Task(Sum, 10, 20); + var result = await taskpool.execute(task); + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass014', 0, async function (done) { + function Add(value1, value2) { + "use concurrent" + if (value1 & value2) + return true; + else + return false; + } + var task = new taskpool.Task(Add, true, true); + var result = await taskpool.execute(task); + expect(result).assertEqual(true); + done(); + }) + + it('TaskPoolTestClass015', 0, async function (done) { + function StrCat(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task = new taskpool.Task(StrCat, "abc", "def"); + var result = await taskpool.execute(task); + expect(result).assertEqual("abcdef"); + done(); + }) + + it('TaskPoolTestClass016', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + function StrCat(value1, value2) { + return value1 + value2; + } + return value1+StrCat(value2,"hello"); + } + var task = new taskpool.Task(Sum, "abc", "def"); + var result = await taskpool.execute(task); + expect(result).assertEqual("abcdefhello"); + done(); + }) + + it('TaskPoolTestClass017', 0, async function (done) { + function Sum(arg1, arg2) { + "use concurrent" + let value = []; + value[0] = arg1[0] + arg2[0]; + value[1] = arg1[1] + arg2[1]; + return value; + } + var task = new taskpool.Task(Sum, [1,2], [3,4]); + var result = await taskpool.execute(task); + expect(result[0]).assertEqual(4); + expect(result[1]).assertEqual(6); + done(); + }) + + it('TaskPoolTestClass018', 0, async function (done) { + function Sum(arg1, arg2) { + "use concurrent" + let value = arg1; + value.a = arg1.a + arg2.a; + value.b = arg1.b + arg2.b; + return value; + } + var task = new taskpool.Task(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}); + var result = await taskpool.execute(task); + expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}"); + done(); + }) + + it('TaskPoolTestClass019', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task = new taskpool.Task(Sum, 10); + var result = await taskpool.execute(task); + expect(result.toString()).assertEqual("NaN"); + done(); + }) + + it('TaskPoolTestClass020', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task = new taskpool.Task(Sum, 10, 20, 30); + var result = await taskpool.execute(task); + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass021', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task = new taskpool.Task(Sum, 10, 20); + var result1 = await taskpool.execute(task); + var result2 = await taskpool.execute(task); + expect(result1).assertEqual(30); + expect(result2).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass022', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task1 = new taskpool.Task(Sum, 10, 20); + var task2 = new taskpool.Task(Sum, 30, 40); + var result1 = await taskpool.execute(task1); + var result2 = await taskpool.execute(task2); + expect(result1).assertEqual(30); + expect(result2).assertEqual(70); + done(); + }) + + it('TaskPoolTestClass023', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task1 = new taskpool.Task(Sum, 10, 20); + var task2 = new taskpool.Task(Sum, 10, 20); + var result1 = await taskpool.execute(task1); + var result2 = await taskpool.execute(task2); + expect(result1).assertEqual(30); + expect(result2).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass024', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + function Multi(value1, value2) { + "use concurrent" + return value1 * value2; + } + var task1 = new taskpool.Task(Sum, 10, 20); + var result1 = await taskpool.execute(task1); + var task2 = new taskpool.Task(Multi, 10, 20); + var result2 = await taskpool.execute(task2); + var task3 = new taskpool.Task(Sum, 10, 30); + var result3 = await taskpool.execute(task3); + var task4 = new taskpool.Task(Multi, 20, 20); + var result4 = await taskpool.execute(task4); + expect(result1).assertEqual(30); + expect(result2).assertEqual(200); + expect(result3).assertEqual(40); + expect(result4).assertEqual(400); + done(); + }) + + it('TaskPoolTestClass025', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result; + var isTerminate = false; + var task = new taskpool.Task(Sum, 10, 20) + taskpool.execute(task).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass026', 0, async function (done) { + function Add(value1, value2) { + "use concurrent" + if (value1 & value2) + return true; + else + return false; + } + var task = new taskpool.Task(Add, true, true) + var result; + var isTerminate = false; + taskpool.execute(task).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result).assertEqual(true); + done(); + }) + + it('TaskPoolTestClass027', 0, async function (done) { + function StrCat(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task = new taskpool.Task(StrCat, "abc", "def") + var result; + var isTerminate = false; + taskpool.execute(task).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result).assertEqual("abcdef"); + done(); + }) + + it('TaskPoolTestClass028', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + function StrCat(value1, value2) { + return value1 + value2; + } + return value1+StrCat(value2,"hello"); + } + var task = new taskpool.Task(Sum, "abc", "def"); + var result; + var isTerminate = false; + taskpool.execute(task).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result).assertEqual("abcdefhello"); + done(); + }) + + it('TaskPoolTestClass029', 0, async function (done) { + function Sum(arg1, arg2) { + "use concurrent" + let value = []; + value[0] = arg1[0] + arg2[0]; + value[1] = arg1[1] + arg2[1]; + return value; + } + var task = new taskpool.Task(Sum, [1,2], [3,4]); + var result; + var isTerminate = false; + taskpool.execute(task).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result[0]).assertEqual(4); + expect(result[1]).assertEqual(6); + done(); + }) + + it('TaskPoolTestClass030', 0, async function (done) { + function Sum(arg1, arg2) { + "use concurrent" + let value = arg1; + value.a = arg1.a + arg2.a; + value.b = arg1.b + arg2.b; + return value; + } + var task = new taskpool.Task(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}); + var result; + var isTerminate = false; + taskpool.execute(task).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}"); + done(); + }) + + it('TaskPoolTestClass031', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task = new taskpool.Task(Sum, 10); + var result; + var isTerminate = false; + taskpool.execute(task).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result.toString()).assertEqual("NaN"); + done(); + }) + + it('TaskPoolTestClass032', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task = new taskpool.Task(Sum, 10, 20, 30); + var result; + var isTerminate = false; + taskpool.execute(task).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass033', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result1; + var result2; + var isTerminate1 = false; + var isTerminate2 = false; + + var task1 = new taskpool.Task(Sum, 10, 20); + taskpool.execute(task1).then((ret1) => { + result1 = ret1; + isTerminate1 = true; + }) + + var task2 = new taskpool.Task(Sum, 30, 40); + taskpool.execute(task2).then((ret2) => { + result2 = ret2; + isTerminate2 = true; + }) + while (!isTerminate1 || !isTerminate2) { + await promiseCase() + } + expect(result1).assertEqual(30); + expect(result2).assertEqual(70); + done(); + }) + + it('TaskPoolTestClass034', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result1; + var result2; + var isTerminate1 = false; + var isTerminate2 = false; + + var task1 = new taskpool.Task(Sum, 10, 20) + taskpool.execute(task1).then((ret1) => { + result1 = ret1; + isTerminate1 = true; + }) + var task2 = new taskpool.Task(Sum, 10, 20) + taskpool.execute(task2).then((ret2) => { + result2 = ret2; + isTerminate2 = true; + }) + while (!isTerminate1 || !isTerminate2) { + await promiseCase() + } + expect(result1).assertEqual(30); + expect(result2).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass035', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result1; + var result2; + var isTerminate1 = false; + var isTerminate2 = false; + + var task = new taskpool.Task(Sum, 10, 20) + taskpool.execute(task).then((ret1) => { + result1 = ret1; + isTerminate1 = true; + }) + taskpool.execute(task).then((ret2) => { + result2 = ret2; + isTerminate2 = true; + }) + while (!isTerminate1 || !isTerminate2) { + await promiseCase() + } + expect(result1).assertEqual(30); + expect(result2).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass036', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + function Multi(value1, value2) { + "use concurrent" + return value1 * value2; + } + + var result1; + var result2; + var result3; + var result4; + var isTerminate1 = false; + var isTerminate2 = false; + var isTerminate3 = false; + var isTerminate4 = false; + + var task1 = new taskpool.Task(Sum, 10, 20) + taskpool.execute(task1).then((ret1) => { + result1 = ret1; + isTerminate1 = true; + }) + var task2 = new taskpool.Task(Multi, 10, 20) + taskpool.execute(task2).then((ret2) => { + result2 = ret2; + isTerminate2 = true; + }) + var task3 = new taskpool.Task(Sum, 10, 30) + taskpool.execute(task3).then((ret3) => { + result3 = ret3; + isTerminate3 = true; + }) + var task4 = new taskpool.Task(Multi, 20, 20) + taskpool.execute(task4).then((ret4) => { + result4 = ret4; + isTerminate4 = true; + }) + + while (!isTerminate1 || !isTerminate2 || !isTerminate3 || !isTerminate4) { + await promiseCase() + } + expect(result1).assertEqual(30); + expect(result2).assertEqual(200); + expect(result3).assertEqual(40); + expect(result4).assertEqual(400); + done(); + }) + + it('TaskPoolTestClass037', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result; + var isTerminate = false; + taskpool.execute(Sum, 10, 20).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass038', 0, async function (done) { + function Add(value1, value2) { + "use concurrent" + if (value1 & value2) + return true; + else + return false; + } + var result; + var isTerminate = false; + taskpool.execute(Add, true, false).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result).assertEqual(false); + done(); + }) + + it('TaskPoolTestClass039', 0, async function (done) { + function StrCat(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result; + var isTerminate = false; + taskpool.execute(StrCat, "abc", "def").then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result).assertEqual("abcdef"); + done(); + }) + + it('TaskPoolTestClass040', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + function StrCat(value1, value2) { + return value1 + value2; + } + return value1+StrCat(value2,"hello"); + } + var result; + var isTerminate = false; + taskpool.execute(Sum, "abc", "def").then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result).assertEqual("abcdefhello"); + done(); + }) + + it('TaskPoolTestClass041', 0, async function (done) { + function Sum(arg1, arg2) { + "use concurrent" + let value = []; + value[0] = arg1[0] + arg2[0]; + value[1] = arg1[1] + arg2[1]; + return value; + } + var result; + var isTerminate = false; + taskpool.execute(Sum, [1,2], [3,4]).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result[0]).assertEqual(4); + expect(result[1]).assertEqual(6); + done(); + }) + + it('TaskPoolTestClass042', 0, async function (done) { + function Sum(arg1, arg2) { + "use concurrent" + let value = arg1; + value.a = arg1.a + arg2.a; + value.b = arg1.b + arg2.b; + return value; + } + var result; + var isTerminate = false; + taskpool.execute(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}"); + done(); + }) + + it('TaskPoolTestClass043', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result; + var isTerminate = false; + taskpool.execute(Sum, 10).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result.toString()).assertEqual("NaN"); + done(); + }) + + it('TaskPoolTestClass044', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result; + var isTerminate = false; + taskpool.execute(Sum, 10, 20, 30).then((ret) => { + result = ret; + isTerminate = true; + }) + while (!isTerminate) { + await promiseCase() + } + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass045', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result1; + var result2; + var isTerminate1 = false; + var isTerminate2 = false; + + taskpool.execute(Sum, 10, 20).then((ret1) => { + result1 = ret1; + isTerminate1 = true; + }) + taskpool.execute(Sum, 30, 40).then((ret2) => { + result2 = ret2; + isTerminate2 = true; + }) + while (!isTerminate1 || !isTerminate2) { + await promiseCase() + } + expect(result1).assertEqual(30); + expect(result2).assertEqual(70); + done(); + }) + + it('TaskPoolTestClass046', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var result1; + var result2; + var isTerminate1 = false; + var isTerminate2 = false; + + taskpool.execute(Sum, 10, 20).then((ret1) => { + result1 = ret1; + isTerminate1 = true; + }) + taskpool.execute(Sum, 10, 20).then((ret2) => { + result2 = ret2; + isTerminate2 = true; + }) + while (!isTerminate1 || !isTerminate2) { + await promiseCase() + } + expect(result1).assertEqual(30); + expect(result2).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass047', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + function Multi(value1, value2) { + "use concurrent" + return value1 * value2; + } + + var result1; + var result2; + var result3; + var result4; + var isTerminate1 = false; + var isTerminate2 = false; + var isTerminate3 = false; + var isTerminate4 = false; + + taskpool.execute(Sum, 10, 20).then((ret1) => { + result1 = ret1; + isTerminate1 = true; + }) + taskpool.execute(Multi, 10, 20).then((ret2) => { + result2 = ret2; + isTerminate2 = true; + }) + taskpool.execute(Sum, 10, 30).then((ret3) => { + result3 = ret3; + isTerminate3 = true; + }) + taskpool.execute(Multi, 20, 20).then((ret4) => { + result4 = ret4; + isTerminate4 = true; + }) + while (!isTerminate1 || !isTerminate2 || !isTerminate3 || !isTerminate4) { + await promiseCase() + } + expect(result1).assertEqual(30); + expect(result2).assertEqual(200); + expect(result3).assertEqual(40); + expect(result4).assertEqual(400); + done(); + }) + + it('TaskPoolTestClass048', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + try { + var result = await taskpool.execute(Sum); + } catch(e) { + expect(e.toString()).assertEqual("BusinessError: taskpool:: first param must be object when argc is one"); + } + done(); + }) + + it('TaskPoolTestClass061', 0, async function (done) { + function Sum(value1, value2) { + "use concurrent" + return value1 + value2; + } + var task1 = new taskpool.Task(Sum, 10, 20); + var task2 = new taskpool.Task(Sum, 30, 40); + var task3 = new taskpool.Task(Sum, 50, 60); + var result1 = await taskpool.execute(task1,taskpool.Priority.LOW); + var result2 = await taskpool.execute(task2,taskpool.Priority.HIGH); + var result3 = await taskpool.execute(task3,taskpool.Priority.MEDIUM); + expect(result1).assertEqual(30); + expect(result2).assertEqual(70); + expect(result3).assertEqual(110); + done(); + }) + + it('TaskPoolTestClass062', 0, async function (done) { + async function func(value1, value2) { + "use concurrent" + let result = await new Promise((resolve, reject) => { + let value = value1 + value2; + resolve(value); + }) + return result; + } + var result = await taskpool.execute(func, 10, 20); + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass063', 0, async function (done) { + async function func(value1, value2) { + "use concurrent" + let result = await new Promise((resolve, reject) => { + let value = value1 + value2; + resolve(value); + }) + return result; + } + var task = new taskpool.Task(func, 10, 20); + var result = await taskpool.execute(task); + expect(result).assertEqual(30); + done(); + }) + + /** + * @tc.number : TaskPoolTestClass049 + * @tc.name : Async Function Cancel task + * @tc.desc : Cancel tasks that have not been executed + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass049', 0, async function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + function additionDelay(arg) { + "use concurrent" + var start = new Date().getTime(); + while (new Date().getTime() - start < 200) { + continue; + } + return arg + 1; + } + try { + var task1 = new taskpool.Task(additionDelay, 100); + var task2 = new taskpool.Task(additionDelay, 200); + var task3 = new taskpool.Task(additionDelay, 200); + var task4 = new taskpool.Task(additionDelay, 200); + var task5 = new taskpool.Task(additionDelay, 200); + var task6 = new taskpool.Task(additionDelay, 200); + var task7 = new taskpool.Task(additionDelay, 200); + var task8 = new taskpool.Task(additionDelay, 200); + var task9 = new taskpool.Task(additionDelay, 200); + var task10 = new taskpool.Task(additionDelay, 200); + var task11 = new taskpool.Task(addition, 300); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + var result3 = taskpool.execute(task3); + var result4 = taskpool.execute(task4); + var result5 = taskpool.execute(task5); + var result6 = taskpool.execute(task6); + var result7 = taskpool.execute(task7); + var result8 = taskpool.execute(task8); + var result9 = taskpool.execute(task9); + var result10 = taskpool.execute(task10); + var result11 = taskpool.execute(task11); + + var start = new Date().getTime(); + while (new Date().getTime() - start < 20) { + continue; + } + + taskpool.cancel(task11); + } + catch (e) { + expect(e.toString()).assertEqual(""); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass050 + * @tc.name : Sync Function Cancel task + * @tc.desc : Cancel tasks that have not been executed + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass050', 0, function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + function additionDelay(arg) { + "use concurrent" + var start = new Date().getTime(); + while (new Date().getTime() - start < 200) { + continue; + } + return arg + 1; + } + try { + var task1 = new taskpool.Task(additionDelay, 100); + var task2 = new taskpool.Task(additionDelay, 200); + var task3 = new taskpool.Task(additionDelay, 200); + var task4 = new taskpool.Task(additionDelay, 200); + var task5 = new taskpool.Task(additionDelay, 200); + var task6 = new taskpool.Task(additionDelay, 200); + var task7 = new taskpool.Task(additionDelay, 200); + var task8 = new taskpool.Task(additionDelay, 200); + var task9 = new taskpool.Task(additionDelay, 200); + var task10 = new taskpool.Task(additionDelay, 200); + var task11 = new taskpool.Task(addition, 300); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + var result3 = taskpool.execute(task3); + var result4 = taskpool.execute(task4); + var result5 = taskpool.execute(task5); + var result6 = taskpool.execute(task6); + var result7 = taskpool.execute(task7); + var result8 = taskpool.execute(task8); + var result9 = taskpool.execute(task9); + var result10 = taskpool.execute(task10); + var result11 = taskpool.execute(task11); + + var start = new Date().getTime(); + while (new Date().getTime() - start < 20) { + continue; + } + + taskpool.cancel(task11); + } + catch (e) { + expect(e.toString()).assertEqual(""); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass051 + * @tc.name : Async Function Cancel task + * @tc.desc : Cancel the task in progress + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass051', 0, async function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + function additionDelay(arg) { + "use concurrent" + var start = new Date().getTime(); + while (new Date().getTime() - start < 3000) { + continue; + } + return arg + 1; + } + try { + var task1 = new taskpool.Task(additionDelay, 100); + var task2 = new taskpool.Task(additionDelay, 200); + var task3 = new taskpool.Task(addition, 300); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + var result3 = taskpool.execute(task3); + + var start = new Date().getTime(); + while (new Date().getTime() - start < 1000) { + continue; + } + + taskpool.cancel(task1); + } + catch (e) { + expect(e.toString()).assertEqual( + "BusinessError: The task is executing when it is canceled, taskpool:: can not cancel the running task"); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass052 + * @tc.name : Sync Function Cancel task + * @tc.desc : Cancel the task in progress + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass052', 0, function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + function additionDelay(arg) { + "use concurrent" + var start = new Date().getTime(); + while (new Date().getTime() - start < 3000) { + continue; + } + return arg + 1; + } + try { + var task1 = new taskpool.Task(additionDelay, 100); + var task2 = new taskpool.Task(additionDelay, 200); + var task3 = new taskpool.Task(addition, 300); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + var result3 = taskpool.execute(task3); + + var start = new Date().getTime(); + while (new Date().getTime() - start < 1000) { + continue; + } + + taskpool.cancel(task1); + } + catch (e) { + expect(e.toString()).assertEqual( + "BusinessError: The task is executing when it is canceled, taskpool:: can not cancel the running task"); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass053 + * @tc.name : Async Function Cancel task + * @tc.desc : Cancel the executed task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass053', 0, async function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + try { + var task1 = new taskpool.Task(addition, 100); + var task2 = new taskpool.Task(addition, 200); + var task3 = new taskpool.Task(addition, 300); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + var result3 = taskpool.execute(task3); + + var start = new Date().getTime(); + while (new Date().getTime() - start < 1000) { + continue; + } + + taskpool.cancel(task1); + } + catch (e) { + expect(e.toString()).assertEqual( + "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass054 + * @tc.name : Sync Function Cancel task + * @tc.desc : Cancel the executed task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass054', 0, function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + try { + var task1 = new taskpool.Task(addition, 100); + var task2 = new taskpool.Task(addition, 200); + var task3 = new taskpool.Task(addition, 300); + var task4 = new taskpool.Task(addition, 400); + var task5 = new taskpool.Task(addition, 500); + var task6 = new taskpool.Task(addition, 600); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + var result3 = taskpool.execute(task3); + var result4 = taskpool.execute(task4); + var result5 = taskpool.execute(task5); + var result6 = taskpool.execute(task6); + + var start = new Date().getTime(); + while (new Date().getTime() - start < 1000) { + continue; + } + + taskpool.cancel(task3); + } + catch (e) { + expect(e.toString()).assertEqual( + "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass055 + * @tc.name : Async Function Cancel task + * @tc.desc : Cancel nonexistent task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass055', 0, async function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + try { + var task1 = new taskpool.Task(addition, 100); + var task2 = new taskpool.Task(addition, 200); + var task3 = new taskpool.Task(addition, 300); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + + taskpool.cancel(task3); + } + catch (e) { + expect(e.toString()).assertEqual( + "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass056 + * @tc.name : Sync Function Cancel task + * @tc.desc : Cancel nonexistent task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass056', 0, function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + try { + var task1 = new taskpool.Task(addition, 100); + var task2 = new taskpool.Task(addition, 200); + var task3 = new taskpool.Task(addition, 300); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + + taskpool.cancel(task3); + } + catch (e) { + expect(e.toString()).assertEqual( + "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass057 + * @tc.name : Async Function Cancel task + * @tc.desc : Canceling unexecuted tasks multiple times + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass057', 0, async function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + function additionDelay(arg) { + "use concurrent" + var start = new Date().getTime(); + while (new Date().getTime() - start < 3000) { + continue; + } + return arg + 1; + } + try { + var task1 = new taskpool.Task(additionDelay, 100); + var task2 = new taskpool.Task(additionDelay, 200); + var task3 = new taskpool.Task(addition, 300); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + var result3 = taskpool.execute(task3); + + var start = new Date().getTime(); + while (new Date().getTime() - start < 1000) { + continue; + } + + taskpool.cancel(task3); + taskpool.cancel(task3); + } + catch (e) { + expect(e.toString()).assertEqual( + "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass058 + * @tc.name : Sync Function Cancel task + * @tc.desc : Canceling unexecuted tasks multiple times + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass058', 0, function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + function additionDelay(arg) { + "use concurrent" + var start = new Date().getTime(); + while (new Date().getTime() - start < 3000) { + continue; + } + return arg + 1; + } + try { + var task1 = new taskpool.Task(additionDelay, 100); + var task2 = new taskpool.Task(additionDelay, 200); + var task3 = new taskpool.Task(addition, 300); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + var result3 = taskpool.execute(task3); + + var start = new Date().getTime(); + while (new Date().getTime() - start < 1000) { + continue; + } + + taskpool.cancel(task3); + taskpool.cancel(task3); + } + catch (e) { + expect(e.toString()).assertEqual( + "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass059 + * @tc.name : Async Function Cancel task + * @tc.desc : Cancel all tasks in sequence + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass059', 0, async function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + try { + var task1 = new taskpool.Task(addition, 100); + var task2 = new taskpool.Task(addition, 200); + var task3 = new taskpool.Task(addition, 300); + var task4 = new taskpool.Task(addition, 400); + var task5 = new taskpool.Task(addition, 500); + var task6 = new taskpool.Task(addition, 600); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + var result3 = taskpool.execute(task3); + var result4 = taskpool.execute(task4); + var result5 = taskpool.execute(task5); + var result6 = taskpool.execute(task6); + + var start = new Date().getTime(); + while (new Date().getTime() - start < 100) { + continue; + } + + taskpool.cancel(task6); + taskpool.cancel(task5); + taskpool.cancel(task4); + taskpool.cancel(task3); + taskpool.cancel(task2); + } + catch (e) { + expect(e.toString()).assertEqual( + "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); + } + done(); + }) + + /** + * @tc.number : TaskPoolTestClass060 + * @tc.name : Sync Function Cancel task + * @tc.desc : Cancel all tasks in sequence + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass060', 0, function (done) { + function addition(arg) { + "use concurrent" + return arg + 1; + } + try { + var task1 = new taskpool.Task(addition, 100); + var task2 = new taskpool.Task(addition, 200); + var task3 = new taskpool.Task(addition, 300); + var task4 = new taskpool.Task(addition, 400); + var task5 = new taskpool.Task(addition, 500); + var task6 = new taskpool.Task(addition, 600); + + var result1 = taskpool.execute(task1); + var result2 = taskpool.execute(task2); + var result3 = taskpool.execute(task3); + var result4 = taskpool.execute(task4); + var result5 = taskpool.execute(task5); + var result6 = taskpool.execute(task6); + + var start = new Date().getTime(); + while (new Date().getTime() - start < 100) { + continue; + } + + taskpool.cancel(task6); + taskpool.cancel(task5); + taskpool.cancel(task4); + taskpool.cancel(task3); + taskpool.cancel(task2); + } + catch (e) { + expect(e.toString()).assertEqual( + "BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task"); + } + done(); + }) +}) } \ No newline at end of file diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/module.json b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..bba3f6b364e7137610bd55a5bbc2cbbc262ddd8c --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_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.taskpool.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/taskpool_lib_standard/entry/src/main/resources/base/element/color.json b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_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/taskpool_lib_standard/entry/src/main/resources/base/element/string.json b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b8416b237de5fe166d47eb8720d73a089b6d9fe0 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_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/taskpool_lib_standard/entry/src/main/resources/base/media/icon.png b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/resources/base/media/icon.png differ diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/resources/base/profile/main_pages.json b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..c1858c216308ad312862a877139a8ba6908ec3c6 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "MainAbility/pages/index" + ] +} diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/config.json b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/config.json deleted file mode 100644 index 38fad0eed7a5f576a9eec0079f8e3196ac3684b9..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/config.json +++ /dev/null @@ -1,97 +0,0 @@ -{ - "app": { - "bundleName": "com.example.taskpool", - "vendor": "example", - "version": { - "code": 1000000, - "name": "1.0.0" - }, - "apiVersion": { - "compatible": 8, - "target": 9 - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.taskpool", - "name": ".entry", - "srcPath": "", - "mainAbility": ".MainAbility", - "deviceType": [ - "tablet", - "default", - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry", - "installationFree": false - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "orientation": "unspecified", - "formsEnabled": false, - "name": ".MainAbility", - "srcLanguage": "js", - "srcPath": "MainAbility", - "icon": "$media:icon", - "description": "$string:MainAbility_desc", - "label": "$string:MainAbility_label", - "type": "page", - "visible": true, - "launchType": "standard" - }, - { - "orientation": "unspecified", - "formsEnabled": false, - "name": ".TestAbility", - "srcLanguage": "js", - "srcPath": "TestAbility", - "icon": "$media:icon", - "description": "$string:TestAbility_desc", - "label": "$string:TestAbility_label", - "type": "page", - "visible": true, - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": true - } - }, - { - "pages": [ - "pages/index/index" - ], - "name": ".TestAbility", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ], - "testRunner": { - "name": "OpenHarmonyTestRunner", - "srcPath": "TestRunner" - } - - } -} \ No newline at end of file diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/i18n/en-US.json b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/i18n/en-US.json deleted file mode 100644 index e63c70d978a3a53be988388c87182f81785e170c..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/i18n/en-US.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "strings": { - "hello": "Hello", - "world": "World" - } -} \ No newline at end of file diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/i18n/zh-CN.json b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/i18n/zh-CN.json deleted file mode 100644 index de6ee5748322f44942c1b003319d8e66c837675f..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/i18n/zh-CN.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "strings": { - "hello": "您好", - "world": "世界" - } -} \ No newline at end of file diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.css b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.css deleted file mode 100644 index 5bcfb2e8b6d4da7f7cdefb090c3eeaccd70009c9..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.css +++ /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. - */ - -.container { - flex-direction: column; - justify-content: center; - align-items: center; -} - -.title { - font-size: 40px; - color: #000000; - opacity: 0.9; -} - -@media screen and (device-type: tablet) and (orientation: landscape) { - .title { - font-size: 100px; - } -} - -@media screen and (device-type: wearable) { - .title { - font-size: 28px; - color: #FFFFFF; - } -} - -@media screen and (device-type: tv) { - .container { - background-image: url("../../common/images/Wallpaper.png"); - background-size: cover; - background-repeat: no-repeat; - background-position: center; - } - - .title { - font-size: 100px; - color: #FFFFFF; - } -} - -@media screen and (device-type: phone) and (orientation: landscape) { - .title { - font-size: 60px; - } -} diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.hml b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.hml deleted file mode 100644 index 81d7b7d182db5b6534a7acd9d76c081efd0d268c..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.hml +++ /dev/null @@ -1,20 +0,0 @@ - - -
- - {{ $t('strings.hello') }} {{title}} - -
\ No newline at end of file diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.js b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.js deleted file mode 100644 index be8d37f06d0178b1de62734cb15c7202d731c29c..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.js +++ /dev/null @@ -1,32 +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 app from '@system.app' -import device from '@system.device' -import router from '@system.router' - -export default { - data: { - title: '' - }, - onInit() { - this.title = this.$t('strings.world'); - }, - onShow() { - console.info('onShow finish'); - }, - onReady() { - }, -} \ No newline at end of file diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/i18n/en-US.json b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/i18n/en-US.json deleted file mode 100644 index 3cb24b374b1d919ca8eac0638f361692b603a900..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_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/taskpool_lib_standard/src/main/js/TestAbility/i18n/zh-CN.json b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/i18n/zh-CN.json deleted file mode 100644 index c804e32c0c3103929baca5617cdac70be11fdba1..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_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/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.css b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.css deleted file mode 100644 index b1bcd43387ba131cc1d30975ff7508a6f8084a4b..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.css +++ /dev/null @@ -1,30 +0,0 @@ -.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; -} - -@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/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.hml b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.hml deleted file mode 100644 index f629c71a9be857db6cdf94149652a191b9b272ea..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.hml +++ /dev/null @@ -1,5 +0,0 @@ -
- - {{ $t('strings.hello') }} {{ title }} - -
diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestRunner/OpenHarmonyTestRunner.js deleted file mode 100644 index ebcd73051be249674f36778ee4dbe3e1af0513b5..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_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'] + '.TestAbility'; - - 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/taskpool_lib_standard/src/main/js/test/List.test.js b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/test/List.test.js deleted file mode 100644 index 78a7e04988e55ea424ae9db408632429b3e55441..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/test/List.test.js +++ /dev/null @@ -1,19 +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 TaskPoolTest from './TaskPool.test.js' -export default function testsuite() { -TaskPoolTest() -} diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/resources/base/element/string.json b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/resources/base/element/string.json deleted file mode 100644 index 47e80f46aed3e6b07360c394f7a246719d2bd830..0000000000000000000000000000000000000000 --- a/commonlibrary/ets_utils/taskpool_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