diff --git a/commonlibrary/ets_utils/BUILD.gn b/commonlibrary/ets_utils/BUILD.gn index fd4dfb407927f01627e20cea570b0019f9d64179..0eb4868afe60b64667bc7f8206a9e817dfd329ce 100644 --- a/commonlibrary/ets_utils/BUILD.gn +++ b/commonlibrary/ets_utils/BUILD.gn @@ -23,6 +23,7 @@ group("ets_utils") { "convertxml_lib_standard:convertxml_js_test", "intl_lib_standard:intl_js_test", "process_lib_standard:process_js_test", + "taskpool_lib_standard:taskPool_js_test", "uri_lib_standard:uri_js_test", "url_lib_standard:url_js_test", "util2_lib_standard:util2_js_test", diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/BUILD.gn b/commonlibrary/ets_utils/taskpool_lib_standard/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..aeace9fd10d0e73338102d792e37f8ebfefa215b --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") +ohos_js_hap_suite("taskPool_js_test") { + hap_profile = "./src/main/config.json" + js2abc = true + deps = [ + ":taskPool_js_assets", + ":taskPool_resources", + ] + + 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_resources("taskPool_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/Test.json b/commonlibrary/ets_utils/taskpool_lib_standard/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..4359811e8a62e67fa32f0d1f17de272ef61a37f3 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for startup taskpool js api Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "800000", + "shell-timeout": "800000", + "bundle-name": "com.example.taskpool", + "package-name": "com.example.taskpool" + }, + "kits": [ + { + "test-file-name": [ + "ActsTaskPoolJSApiTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/signature/openharmony_sx.p7b b/commonlibrary/ets_utils/taskpool_lib_standard/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..8c5a6398c8f35b09aaec99af9caa1d7a752621b2 Binary files /dev/null and b/commonlibrary/ets_utils/taskpool_lib_standard/signature/openharmony_sx.p7b differ diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/config.json b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..ce9198b557328549e9dd55f29e6c69ff3d8e4a6a --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/config.json @@ -0,0 +1,97 @@ +{ + "app": { + "bundleName": "com.example.childprocess", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 9, + "target": 9 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.childprocess", + "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/app.js b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..ff2c11965e08dd2df603562158980963c00e7a25 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/app.js @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; 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 new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "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 new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "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 new file mode 100644 index 0000000000000000000000000000000000000000..5bcfb2e8b6d4da7f7cdefb090c3eeaccd70009c9 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,59 @@ +/* + * 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 new file mode 100644 index 0000000000000000000000000000000000000000..81d7b7d182db5b6534a7acd9d76c081efd0d268c --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,20 @@ + + +
+ + {{ $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 new file mode 100644 index 0000000000000000000000000000000000000000..be8d37f06d0178b1de62734cb15c7202d731c29c --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,32 @@ +/* + * 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/app.js b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..e4d30d4ed362459e8ae4e3e1f5e697e73c96d124 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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"); + } +}; 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 new file mode 100644 index 0000000000000000000000000000000000000000..3cb24b374b1d919ca8eac0638f361692b603a900 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "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 new file mode 100644 index 0000000000000000000000000000000000000000..c804e32c0c3103929baca5617cdac70be11fdba1 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "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 new file mode 100644 index 0000000000000000000000000000000000000000..b1bcd43387ba131cc1d30975ff7508a6f8084a4b --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.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 new file mode 100644 index 0000000000000000000000000000000000000000..f629c71a9be857db6cdf94149652a191b9b272ea --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.js b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..88b083a7f6b979019d6a2c5ad20b19c5fd43286b --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * 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'); + } +} + + + 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 new file mode 100644 index 0000000000000000000000000000000000000000..ebcd73051be249674f36778ee4dbe3e1af0513b5 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * 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 new file mode 100644 index 0000000000000000000000000000000000000000..78a7e04988e55ea424ae9db408632429b3e55441 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/test/List.test.js @@ -0,0 +1,19 @@ +/* + * 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/js/test/TaskPool.test.js b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/test/TaskPool.test.js new file mode 100644 index 0000000000000000000000000000000000000000..09884fa2223f898f9e91d408705cd490bf8235c2 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/js/test/TaskPool.test.js @@ -0,0 +1,638 @@ +/* + * 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' +import worker from "@ohos.worker" +export default function TaskPoolTest() { +describe('ActsAbilityTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + + it('TaskPoolTestClass001', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + var result = await taskpool.execute(Sum, 10, 20); + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass002', 0, async function () { + function Add(value1, value2) { + 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 () { + function StrCat(value1, value2) { + return value1 + value2; + } + var result = await taskpool.execute(StrCat, "abc", "def"); + expect(result).assertEqual("abcdef"); + done(); + }) + + it('TaskPoolTestClass004', 0, async function () { + function StrCat(value1, value2) { + 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 () { + function Sum(value1, value2) { + 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 () { + function Sum(arg1, arg2) { + 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 () { + function Sum(arg1, arg2) { + 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 () { + function Sum(value1, value2) { + return value1 + value2; + } + var result = await taskpool.execute(Sum, 10); + expect(result.toString()).assertEqual("NaN"); + done(); + }) + + it('TaskPoolTestClass009', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + var result = await taskpool.execute(Sum, 10, 20, 30); + expect(result).assertEqual(30); + done(); + }) + + it('TaskPoolTestClass010', 0, async function () { + function Sum(value1, value2) { + 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 () { + function Sum(value1, value2) { + 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 () { + function Sum(value1, value2) { + return value1 + value2; + } + function Multi(value1, value2) { + 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 () { + function Sum(value1, value2) { + 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 () { + function Add(value1, value2) { + 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 () { + function StrCat(value1, value2) { + 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 () { + function Sum(value1, value2) { + 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 () { + function Sum(arg1, arg2) { + 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 () { + function Sum(arg1, arg2) { + 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 () { + function Sum(value1, value2) { + 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 () { + function Sum(value1, value2) { + 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 () { + function Sum(value1, value2) { + 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 () { + function Sum(value1, value2) { + 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 () { + function Sum(value1, value2) { + 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 () { + function Sum(value1, value2) { + return value1 + value2; + } + function Multi(value1, value2) { + 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 () { + function Sum(value1, value2) { + return value1 + value2; + } + var task = new taskpool.Task(Sum, 10, 20) + taskpool.execute(task).then((ret) => { + expect(ret).assertEqual(30); + }) + done(); + }) + + it('TaskPoolTestClass026', 0, async function () { + function Add(value1, value2) { + if (value1 & value2) + return true; + else + return false; + } + var task = new taskpool.Task(Add, true, true) + taskpool.execute(task).then((ret) => { + expect(ret).assertEqual(true); + }) + done(); + }) + + it('TaskPoolTestClass027', 0, async function () { + function StrCat(value1, value2) { + return value1 + value2; + } + var task = new taskpool.Task(StrCat, "abc", "def") + taskpool.execute(task).then((ret) => { + expect(ret).assertEqual("abcdef"); + }) + done(); + }) + + it('TaskPoolTestClass028', 0, async function () { + function Sum(value1, value2) { + function StrCat(value1, value2) { + return value1 + value2; + } + return value1+StrCat(value2,"hello"); + } + var task = new taskpool.Task(Sum, "abc", "def"); + taskpool.execute(task).then((ret) => { + expect(ret).assertEqual("abcdefhello"); + }) + done(); + }) + + it('TaskPoolTestClass029', 0, async function () { + function Sum(arg1, arg2) { + 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]); + taskpool.execute(task).then((ret) => { + expect(ret[0]).assertEqual(4); + expect(ret[1]).assertEqual(6); + }) + done(); + }) + + it('TaskPoolTestClass030', 0, async function () { + function Sum(arg1, arg2) { + 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}); + taskpool.execute(task).then((ret) => { + expect(JSON.stringify(ret)).assertEqual("{\"a\":4,\"b\":6}"); + }) + done(); + }) + + it('TaskPoolTestClass031', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + var task = new taskpool.Task(Sum, 10); + taskpool.execute(task).then((ret) => { + expect(ret).assertEqual(NaN); + }) + done(); + }) + + it('TaskPoolTestClass032', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + var task = new taskpool.Task(Sum, 10, 20, 30); + taskpool.execute(task).then((ret) => { + expect(ret).assertEqual(30); + }) + done(); + }) + + it('TaskPoolTestClass033', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + var task1 = new taskpool.Task(Sum, 10, 20); + taskpool.execute(task1).then((ret1) => { + expect(ret1).assertEqual(30); + }) + + var task2 = new taskpool.Task(Sum, 30, 40); + taskpool.execute(task2).then((ret2) => { + expect(ret2).assertEqual(70); + }) + done(); + }) + + it('TaskPoolTestClass034', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + var task1 = new taskpool.Task(Sum, 10, 20) + taskpool.execute(task1).then((ret1) => { + expect(ret1).assertEqual(30); + }) + + var task2 = new taskpool.Task(Sum, 10, 20) + taskpool.execute(task2).then((ret2) => { + expect(ret2).assertEqual(30); + }) + done(); + }) + + it('TaskPoolTestClass035', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + var task = new taskpool.Task(Sum, 10, 20) + taskpool.execute(task).then((ret1) => { + expect(ret1).assertEqual(30); + }) + taskpool.execute(task).then((ret2) => { + expect(ret2).assertEqual(30); + }) + done(); + }) + + it('TaskPoolTestClass036', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + function Multi(value1, value2) { + return value1 * value2; + } + + var task1 = new taskpool.Task(Sum, 10, 20) + taskpool.execute(task1).then((ret1) => { + expect(ret1).assertEqual(30); + }) + var task2 = new taskpool.Task(Multi, 10, 20) + taskpool.execute(task2).then((ret2) => { + expect(ret2).assertEqual(200); + }) + var task3 = new taskpool.Task(Sum, 10, 30) + taskpool.execute(task3).then((ret3) => { + expect(ret3).assertEqual(40); + }) + var task4 = new taskpool.Task(Multi, 20, 20) + taskpool.execute(task4).then((ret4) => { + expect(ret4).assertEqual(400); + }) + done(); + }) + + it('TaskPoolTestClass037', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + taskpool.execute(Sum, 10, 20).then((ret) => { + expect(ret).assertEqual(30); + }) + done(); + }) + + it('TaskPoolTestClass038', 0, async function () { + function Add(value1, value2) { + if (value1 & value2) + return true; + else + return false; + } + taskpool.execute(Add, true, false).then((ret) => { + expect(ret).assertEqual(false); + }) + done(); + }) + + it('TaskPoolTestClass039', 0, async function () { + function StrCat(value1, value2) { + return value1 + value2; + } + taskpool.execute(StrCat, "abc", "def").then((ret) => { + expect(ret).assertEqual("abcdef"); + }) + done(); + }) + + it('TaskPoolTestClass040', 0, async function () { + function Sum(value1, value2) { + function StrCat(value1, value2) { + return value1 + value2; + } + return value1+StrCat(value2,"hello"); + } + taskpool.execute(Sum, "abc", "def").then((ret) => { + expect(ret).assertEqual("abcdefhello"); + }) + done(); + }) + + it('TaskPoolTestClass041', 0, async function () { + function Sum(arg1, arg2) { + let value = []; + value[0] = arg1[0] + arg2[0]; + value[1] = arg1[1] + arg2[1]; + return value; + } + taskpool.execute(Sum, [1,2], [3,4]).then((ret) => { + expect(ret[0]).assertEqual(4); + expect(ret[1]).assertEqual(6); + }) + done(); + }) + + it('TaskPoolTestClass042', 0, async function () { + function Sum(arg1, arg2) { + let value = arg1; + value.a = arg1.a + arg2.a; + value.b = arg1.b + arg2.b; + return value; + } + taskpool.execute(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}).then((ret) => { + expect(JSON.stringify(ret)).assertEqual("{\"a\":4,\"b\":6}"); + }) + done(); + }) + + it('TaskPoolTestClass043', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + taskpool.execute(Sum, 10).then((ret) => { + expect(ret).assertEqual(NaN); + }) + done(); + }) + + it('TaskPoolTestClass044', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + taskpool.execute(Sum, 10, 20, 30).then((ret) => { + expect(ret).assertEqual(30); + }) + done(); + }) + + it('TaskPoolTestClass045', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + taskpool.execute(Sum, 10, 20).then((ret1) => { + expect(ret1).assertEqual(30); + }) + taskpool.execute(Sum, 30, 40).then((ret2) => { + expect(ret2).assertEqual(70); + }) + done(); + }) + + it('TaskPoolTestClass046', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + taskpool.execute(Sum, 10, 20).then((ret1) => { + expect(ret1).assertEqual(30); + }) + taskpool.execute(Sum, 10, 20).then((ret2) => { + expect(ret2).assertEqual(30); + }) + done(); + }) + + it('TaskPoolTestClass047', 0, async function () { + function Sum(value1, value2) { + return value1 + value2; + } + function Multi(value1, value2) { + return value1 * value2; + } + + taskpool.execute(Sum, 10, 20).then((ret1) => { + expect(ret1).assertEqual(30); + }) + taskpool.execute(Multi, 10, 20).then((ret2) => { + expect(ret2).assertEqual(200); + }) + taskpool.execute(Sum, 10, 30).then((ret3) => { + expect(ret3).assertEqual(40); + }) + taskpool.execute(Multi, 20, 20).then((ret4) => { + expect(ret4).assertEqual(400); + }) + done(); + }) + + it('TaskPoolTestClass048', 0, async function () { + function Sum(value1, value2) { + 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(); + }) +}) +} \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..47e80f46aed3e6b07360c394f7a246719d2bd830 --- /dev/null +++ b/commonlibrary/ets_utils/taskpool_lib_standard/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "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 diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/src/main/resources/base/media/icon.png b/commonlibrary/ets_utils/taskpool_lib_standard/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/src/main/resources/base/media/icon.png differ