提交 256c616a 编写于 作者: H hu0475

完成commonlibrary子系统ohos.util.Queue、ohos.util.Stack、ohos.taskpool模块的跨平台测试套

Signed-off-by: Nhu0475 <huyanqiang5@huawei.com>
上级 0c224c4c
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Copyright (C) 2023 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
......@@ -16,6 +16,7 @@ group("commonlibrary") {
testonly = true
if (is_standard_system) {
deps = [
"crossplatform:crossplatform",
"ets_utils:ets_utils",
"toolchain:toolchain",
]
......
# Copyright (C) 2023 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")
group("crossplatform") {
testonly = true
if (is_standard_system) {
deps = [
"commonlibraryqueueetstest:ActsCrossplatformCommonlibraryQueueTest",
"commonlibrarystacketstest:ActsCrossplatformCommonlibraryStackTest",
"commonlibrarytaskpooletstest:ActsCrossplatformCommonlibraryTaskpoolTest",
]
}
}
{
"app": {
"bundleName": "ohos.acts.commonlibrary.crossplatform.queue.normal",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (C) 2023 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("ActsCrossplatformCommonlibraryQueueTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCrossplatformCommonlibraryQueueTest"
subsystem_name = "commonlibrary"
part_name = "ets_utils"
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "ohos.acts.commonlibrary.crossplatform.queue.normal",
"module-name": "entry_test"
},
"kits": [
{
"test-file-name": [
"ActsCrossplatformCommonlibraryQueueTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', '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
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 QueueTest from './Queue.test'
export default function testsuite() {
QueueTest()
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 Queue from "@ohos.util.Queue";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
export default function QueueTest() {
describe("QueueTest", function () {
/**
* @tc.number: TEST_CONSTRUCTOR_001
* @tc.name: testConstructor001
* @tc.desc: Create an Queue instance. For example: let queue = new Queue().
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testConstructor001", 0, function () {
try {
let queue = new Queue();
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The Queue's constructor cannot be directly invoked");
}
});
/**
* @tc.number: TEST_ADD_001
* @tc.name: testAdd001
* @tc.desc: Add element to Queue instance end. For example: queue.add("四").
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testAdd001", 0, function () {
let queue = new Queue();
queue.add("四");
let res = queue.getFirst();
expect(res).assertEqual("四");
});
/**
* @tc.number: TEST_ADD_002
* @tc.name: testAdd002
* @tc.desc: Add element to Queue instance end. For example: queue.add(8).
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testAdd002", 0, function () {
let queue = new Queue();
queue.add(8);
let res = queue.getFirst();
expect(res).assertEqual(8);
});
/**
* @tc.number: TEST_ADD_003
* @tc.name: testAdd003
* @tc.desc: Add element to Queue instance end. For example: queue.add(8).
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testAdd003", 0, function () {
let queue = new Queue();
let a = ["a", "b", "c"];
queue.add(a);
let res = queue.getFirst();
expect(res).assertEqual(a);
});
/**
* @tc.number: TEST_ADD_004
* @tc.name: testAdd004
* @tc.desc: Add element to Queue instance end. For example: queue.add("$").
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testAdd004", 0, function () {
let queue = new Queue();
queue.add("$");
let res = queue.getFirst();
expect(res).assertEqual("$");
});
/**
* @tc.number: TEST_ADD_005
* @tc.name: testAdd005
* @tc.desc: Add element to Queue instance end. For example: queue.add(" ").
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testAdd005", 0, function () {
let queue = new Queue();
queue.add(" ");
let res = queue.getFirst();
expect(res).assertEqual(" ");
});
/**
* @tc.number: TEST_ADD_006
* @tc.name: testAdd006
* @tc.desc: Add element to Queue instance end. For example: queue.add(null).
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testAdd006", 0, function () {
let queue = new Queue();
queue.add(null);
let res = queue.getFirst();
expect(res).assertEqual(null);
});
/**
* @tc.number: TEST_ADD_007
* @tc.name: testAdd007
* @tc.desc: Add element to Queue instance end. For example: queue.add(undefined).
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testAdd007", 0, function () {
let queue = new Queue();
queue.add(undefined);
let res = queue.getFirst();
expect(res).assertEqual(undefined);
});
/**
* @tc.number: TEST_ADD_008
* @tc.name: testAdd008
* @tc.desc: Add element to Queue instance end. For example: for (let i = 0; i < 100; i++) { queue.add(i);}.
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testAdd008", 0, function () {
let queue = new Queue();
for (let i = 0; i < 100; i++) {
queue.add(i);
}
let res = queue.length;
expect(res).assertEqual(100);
});
/**
* @tc.number: TEST_ADD_009
* @tc.name: testAdd009
* @tc.desc: Add element to Queue instance end. For example: queue.add.bind({}, 10)().
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testAdd009", 0, function () {
let queue = new Queue();
try {
queue.add.bind({}, 10)();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The add method cannot be bound`);
}
});
/**
* @tc.number: TEST_GET_FIRST_001
* @tc.name: testGetFirst001
* @tc.desc: Get the header element of the queue instance. For example: queue.getFirst().
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testGetFirst001", 0, function () {
let queue = new Queue();
queue.add(6);
queue.add("四");
let res = queue.getFirst();
expect(res).assertEqual(6);
});
/**
* @tc.number: TEST_GET_FIRST_002
* @tc.name: testGetFirst002
* @tc.desc: Get the header element of the queue instance. For example: queue.getFirst().
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testGetFirst002", 0, function () {
let queue = new Queue();
let res = queue.getFirst();
expect(res).assertEqual(undefined);
});
/**
* @tc.number: TEST_POP_001
* @tc.name: testPop001
* @tc.desc: Delete the header element of a queue instance. For example: queue.pop().
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testPop001", 0, function () {
let queue = new Queue();
queue.add(6);
queue.add("四");
let res = queue.pop();
let res1 = queue.getFirst();
expect(res).assertEqual(6);
expect(res1).assertEqual("四");
});
/**
* @tc.number: TEST_POP_002
* @tc.name: testPop002
* @tc.desc: Delete the header element of a queue instance. For example: queue.pop().
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testPop002", 0, function () {
let queue = new Queue();
let res = queue.pop();
expect(res).assertEqual(undefined);
});
/**
* @tc.number: TEST_FOREACH_001
* @tc.name: testForEach001
* @tc.desc: Traversing elements in queue instances. For example: queue.forEach((item, index) => {arr.push(item);}).
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testForEach001", 0, function () {
let queue = new Queue();
queue.add(8);
queue.add("一");
queue.add("二");
queue.add(1);
queue.add(2);
queue.add(3);
queue.add(4);
queue.add(5);
queue.add(6);
let c = ["a", "b", "c", "d"];
queue.add(c);
let arr = [];
queue.forEach((item, index) => {
arr.push(item);
});
let a = [8, "一", "二", 1, 2, 3, 4, 5, 6, c];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_FOREACH_002
* @tc.name: testForEach002
* @tc.desc: Traversing elements in queue instances. For example: queue.forEach((item, index) => {arr.push(item);}).
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testForEach002", 0, function () {
let queue = new Queue();
let arr = [];
queue.forEach((item, index) => {
arr.push(item);
});
expect(arr.length).assertEqual(0);
});
/**
* @tc.number: TEST_ITERATOR_001
* @tc.name: testIterator001
* @tc.desc: Iterate over all elements in the queue instance. For example: for (let item of queue) { arr.push(item);}.
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testIterator001", 0, function () {
let queue = new Queue();
queue.add(8);
queue.add("一");
queue.add("二");
queue.add(5);
queue.add(6);
queue.add("三");
queue.add("四");
let arr = [];
for (let item of queue) {
arr.push(item);
}
let a = [8, "一", "二", 5, 6, "三", "四"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_ITERATOR_002
* @tc.name: testIterator002
* @tc.desc: Iterate over all elements in the queue instance. For example: for (let item of queue) { arr.push(item);}.
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testIterator002", 0, function () {
let queue = new Queue();
let arr = [];
for (let item of queue) {
arr.push(item);
}
expect(arr.length).assertEqual(0);
});
/**
* @tc.number: TEST_ITERATOR_003
* @tc.name: testIterator003
* @tc.desc: Iterate over all elements in the queue instance. For example: queue[Symbol.iterator]().
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 2
*/
it("testIterator003", 0, function () {
let queue = new Queue();
queue.add(8);
queue.add("一");
queue.add("二");
queue.add(5);
queue.add(6);
queue.add("三");
queue.add("四");
let arr = [];
let size = queue.length;
let itr = queue[Symbol.iterator]();
for (let i = 0; i < size; i++) {
arr.push(itr.next().value);
}
let a = [8, "一", "二", 5, 6, "三", "四"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_LENGTH_001
* @tc.name: testLength001
* @tc.desc: Get the number of elements in the queue instance. For example: queue.length.
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 0
*/
it("testLength001", 0, function () {
let queue = new Queue();
queue.add(8);
queue.add("一");
queue.add("二");
queue.add(1);
queue.add(2);
queue.add(3);
queue.add(4);
queue.add(5);
queue.add(6);
let res = queue.length;
expect(9).assertEqual(res);
});
/**
* @tc.number: TEST_LENGTH_002
* @tc.name: testLength002
* @tc.desc: Get the number of elements in the queue instance. For example: queue.length.
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 0
*/
it("testLength001", 0, function () {
let queue = new Queue();
let res = queue.length;
expect(0).assertEqual(res);
});
});
}
{
"module": {
"name": "entry_test",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.commonlibrary.crossplatform.stack.normal",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (C) 2023 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("ActsCrossplatformCommonlibraryStackTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCrossplatformCommonlibraryStackTest"
subsystem_name = "commonlibrary"
part_name = "ets_utils"
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "ohos.acts.commonlibrary.crossplatform.stack.normal",
"module-name": "entry_test"
},
"kits": [
{
"test-file-name": [
"ActsCrossplatformCommonlibraryStackTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', '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
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 StackTest from './Stack.test'
export default function testsuite() {
StackTest()
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 Stack from "@ohos.util.Stack";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
export default function StackTest() {
describe("StackTest", function () {
/**
* @tc.name: testConstructor001
* @tc.desc: Create an Stack instance. For example: let stack = new Stack().
*/
it("testConstructor001", 0, function () {
try {
let stack = new Stack();
expect(stack != undefined).assertEqual(true);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The Stack's constructor cannot be directly invoked");
}
});
/**
* @tc.name: testPush002
* @tc.desc: Insert element at top of stack.For example: stack.push("四").
*/
it("testPush002", 0, function () {
let stack = new Stack();
stack.push("四");
let res = stack.peek();
expect(res).assertEqual("四");
});
/**
* @tc.name: testPush003
* @tc.desc: Insert element at top of stack.For example: stack.push(8).
*/
it("testPush003", 0, function () {
let stack = new Stack();
stack.push(8);
let res = stack.peek();
expect(res).assertEqual(8);
});
/**
* @tc.name: testPush004
* @tc.desc: Insert element at top of stack.For example: let a = {name: "lala", age: "13岁"}; stack.push(a).
*/
it("testPush004", 0, function () {
let stack = new Stack();
let a = {name: "lala", age: "13岁"};
stack.push(a);
let res = stack.peek();
expect(res).assertEqual(a);
});
/**
* @tc.name: testPush005
* @tc.desc: Insert element at top of stack.For example: let a = [1, 2, 3, 4]; stack.push(a).
*/
it("testPush005", 0, function () {
let stack = new Stack();
let a = [1, 2, 3, 4];
stack.push(a);
let res = stack.peek();
expect(res).assertEqual(a);
});
/**
* @tc.name: testPeek006
* @tc.desc: Get stack top element. For example: stack.peek().
*/
it("testPeek006", 0, function () {
let stack = new Stack();
let a = [1, 2, 3, 4];
stack.push(a);
stack.push("A");
stack.push("B");
stack.push(1);
let res = stack.peek();
expect(res).assertEqual(1);
});
/**
* @tc.name: testLocate007
* @tc.desc: Get the index corresponding to the element in the stack. For example: stack.locate("A").
*/
it("testLocate007", 0, function () {
let stack = new Stack();
let a = [1, 2, 3, 4];
stack.push(8);
stack.push(a);
stack.push("A");
stack.push("B");
stack.push(1);
let res = stack.locate("A");
let res1 = stack.locate("C");
expect(res).assertEqual(2);
expect(res1).assertEqual(-1);
});
/**
* @tc.name: testPop008
* @tc.desc: Delete top of stack element. For example: stack.pop().
*/
it("testPop008", 0, function () {
let stack = new Stack();
stack.push("B");
stack.push(1);
let res = stack.pop();
let res1 = stack.peek();
expect(res).assertEqual(1);
expect(res1).assertEqual("B");
});
/**
* @tc.name: testForEach009
* @tc.desc: Traversing elements in stack instances. For example: stack.forEach((item, index) => {arr.push(item);}).
*/
it("testForEach009", 0, function () {
let stack = new Stack();
stack.push(8);
stack.push("三");
stack.push(5);
let c = {name: "lili", age: "13"};
stack.push(c);
stack.push(6);
stack.push("四");
let arr = [];
stack.forEach((item, index) => {
arr.push(item);
});
let a = [8, "三", 5, c, 6, "四"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.name: testIterator010
* @tc.desc: Iterate over all elements in the stack instance. For example: for (let item of stack) {arr.push(item);}.
*/
it("testIterator010", 0, function () {
let stack = new Stack();
stack.push(8);
stack.push("一");
stack.push("二");
stack.push(5);
let c = [1, 2, 3, 4];
stack.push(c);
stack.push(6);
stack.push("三");
stack.push("四");
let arr = [];
for (let item of stack) {
arr.push(item);
}
let a = [8, "一", "二", 5, c, 6, "三", "四"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.name: testLength011
* @tc.desc: Get the number of elements in the stack instance. For example: stack.length.
*/
it("testLength011", 0, function () {
let stack = new Stack();
stack.push(8);
stack.push("一");
stack.push("二");
stack.push(5);
let res = stack.length;
expect(4).assertEqual(res);
});
/**
* @tc.name: testLength012
* @tc.desc: Get the number of elements in the stack instance. For example: stack.length.
*/
it("testLength012", 0, function () {
let stack = new Stack();
let res = stack.length;
expect(0).assertEqual(res);
});
/**
* @tc.name: testIsEmpty013
* @tc.desc: Determine whether the Stack instance is empty. For example: stack.isEmpty().
*/
it("testIsEmpty013", 0, function () {
let stack = new Stack();
stack.push(8);
stack.push("一");
stack.push("二");
stack.push(5);
let res = stack.isEmpty();
expect(res).assertEqual(false);
});
/**
* @tc.name: testIsEmpty014
* @tc.desc: Determine whether the Stack instance is empty. For example: stack.isEmpty().
*/
it("testIsEmpty014", 0, function () {
let stack = new Stack();
let res = stack.isEmpty();
expect(res).assertEqual(true);
});
/**
* @tc.name: testPush015
* @tc.desc: Insert element at top of stack.For example: stack.push("你好世界").
*/
it("testPush015", 0, function () {
let stack = new Stack();
stack.push("你好世界");
let res = stack.peek();
expect(res).assertEqual("你好世界");
});
/**
* @tc.name: testPush016
* @tc.desc: Insert element at top of stack.For example: stack.push(1234).
*/
it("testPush016", 0, function () {
let stack = new Stack();
stack.push(1234);
let res = stack.peek();
expect(res).assertEqual(1234);
});
/**
* @tc.name: testPush017
* @tc.desc: Insert element at top of stack.For example: stack.push(1.234).
*/
it("testPush017", 0, function () {
let stack = new Stack();
stack.push(1.234);
let res = stack.peek();
expect(res).assertEqual(1.234);
});
/**
* @tc.name: testPush018
* @tc.desc: Insert element at top of stack.For example: stack.push(-1234).
*/
it("testPush018", 0, function () {
let stack = new Stack();
stack.push(-1234);
let res = stack.peek();
expect(res).assertEqual(-1234);
});
/**
* @tc.name: testPush019
* @tc.desc: Insert element at top of stack.For example: stack.push(0).
*/
it("testPush019", 0, function () {
let stack = new Stack();
stack.push(0);
let res = stack.peek();
expect(res).assertEqual(0);
});
/**
* @tc.name: testPush020
* @tc.desc: Insert element at top of stack.For example: stack.push("*").
*/
it("testPush020", 0, function () {
let stack = new Stack();
stack.push(10);
stack.push(3.14);
stack.push(-2);
stack.push("AB");
stack.push("*");
let res = stack.peek();
expect(res).assertEqual("*");
});
/**
* @tc.name: testPush021
* @tc.desc: Insert element at top of stack.For example: let arr = {}; stack.push(arr).
*/
it("testPush021", 0, function () {
let stack = new Stack();
let arr = {};
stack.push(arr);
let res = stack.peek();
expect(res).assertEqual(arr);
});
/**
* @tc.name: testPush022
* @tc.desc: Insert element at top of stack.For example: let arr = []; stack.push(arr).
*/
it("testPush022", 0, function () {
let stack = new Stack();
let arr = [];
stack.push(arr);
let res = stack.peek();
expect(res).assertEqual(arr);
});
/**
* @tc.name: testPush023
* @tc.desc: Insert element at top of stack.For example: stack.push("hello world").
*/
it("testPush023", 0, function () {
let stack = new Stack();
stack.push("hello world");
let res = stack.peek();
expect(res).assertEqual("hello world");
});
/**
* @tc.name: testPush024
* @tc.desc: Insert element at top of stack.
*/
it("testPush024", 0, function () {
let stack = new Stack();
stack.push("~!@#$^&*()_+-*/=.?<>:;|{}[]");
let res = stack.peek();
expect(res).assertEqual("~!@#$^&*()_+-*/=.?<>:;|{}[]");
});
/**
* @tc.name: testPush025
* @tc.desc: Insert element at top of stack. For example: stack.push("").
*/
it("testPush025", 0, function () {
let stack = new Stack();
stack.push("");
let res = stack.peek();
expect(res).assertEqual("");
});
/**
* @tc.name: testPush026
* @tc.desc: Insert element at top of stack. For example: stack.push(true).
*/
it("testPush026", 0, function () {
let stack = new Stack();
stack.push(true);
let res = stack.peek();
expect(res).assertEqual(true);
});
/**
* @tc.name: testPush027
* @tc.desc: Insert element at top of stack. For example: stack.push(false).
*/
it("testPush027", 0, function () {
let stack = new Stack();
stack.push(false);
let res = stack.peek();
expect(res).assertEqual(false);
});
/**
* @tc.name: testPush028
* @tc.desc: Insert element at top of stack. For example: stack.push(null).
*/
it("testPush028", 0, function () {
let stack = new Stack();
stack.push(null);
let res = stack.peek();
expect(res).assertEqual(null);
});
/**
* @tc.name: testPush029
* @tc.desc: Insert element at top of stack. For example: stack.push(undefined).
*/
it("testPush029", 0, function () {
let stack = new Stack();
stack.push(undefined);
let res = stack.peek();
expect(res).assertEqual(undefined);
});
/**
* @tc.name: testPeek030
* @tc.desc: Get stack top element. For example: stack.peek().
*/
it("testPeek030", 0, function () {
let stack = new Stack();
let res = stack.peek();
expect(res).assertEqual(undefined);
});
/**
* @tc.name: testPop031
* @tc.desc: Delete top of stack element. For example: stack.pop().
*/
it("testPop031", 0, function () {
let stack = new Stack();
let res = stack.pop();
expect(res).assertEqual(undefined);
});
/**
* @tc.name: testForEach032
* @tc.desc: Traversing elements in stack instances. For example: stack.forEach((item, index) => {arr.push(item);}).
*/
it("testForEach032", 0, function () {
let stack = new Stack();
let arr = [];
stack.forEach((item, index) => {
arr.push(item);
});
expect(arr.length).assertEqual(0);
});
/**
* @tc.name: testIterator033
* @tc.desc: Iterate over all elements in the stack instance. For example: for (let item of stack) {arr.push(item);}.
*/
it("testIterator033", 0, function () {
let stack = new Stack();
let arr = [];
for (let item of stack) {
arr.push(item);
}
expect(arr.length).assertEqual(0);
});
/**
* @tc.name: testPush034
* @tc.desc: Insert element at top of stack. For example: for (let i = 0; i < 1000; i++) {stack.push(i);}.
*/
it("testPush034", 0, function () {
let stack = new Stack();
for (let i = 0; i < 1000; i++) {
stack.push(i);
}
let res = stack.length;
expect(res).assertEqual(1000);
let res1 = stack.peek();
expect(res1).assertEqual(999);
});
/**
* @tc.name: testIterator035
* @tc.desc: Iterate over all elements in the stack instance. For example: stack[Symbol.iterator]().
*/
it("testIterator035", 0, function () {
let stack = new Stack();
stack.push(8);
stack.push("一");
stack.push("二");
stack.push(5);
let c = [1, 2, 3, 4];
stack.push(c);
stack.push(6);
stack.push("三");
stack.push("四");
let arr = [];
let itr = stack[Symbol.iterator]();
let tmp = undefined;
do {
tmp = itr.next().value;
arr.push(tmp);
} while (tmp != undefined);
let a = [8, "一", "二", 5, c, 6, "三", "四"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.name: testPush036
* @tc.desc: Insert element at top of stack. For example: stack.push.bind({}, 10)().
*/
it("testPush036 ", 0, function () {
let stack = new Stack();
try {
stack.push.bind({}, 10)();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The push method cannot be bound`);
}
});
/**
* @tc.name: testIsEmpty037
* @tc.desc: Determine whether the Stack instance is empty. For example: stack.isEmpty.bind({}, "a")().
*/
it('testIsEmpty037', 0, function () {
let stack = new Stack();
try {
stack.isEmpty.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The isEmpty method cannot be bound`);
}
});
/**
* @tc.name: testPop038
* @tc.desc: Delete top of stack element. For example: stack.pop.bind({}, "a")().
*/
it('testPop038', 0, function () {
let stack = new Stack();
try {
stack.pop.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The pop method cannot be bound`);
}
});
});
}
{
"module": {
"name": "entry_test",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.commonlibrary.crossplatform.taskpool.normal",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (C) 2023 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("ActsCrossplatformCommonlibraryTaskpoolTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCrossplatformCommonlibraryTaskpoolTest"
subsystem_name = "commonlibrary"
part_name = "ets_utils"
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "ohos.acts.commonlibrary.crossplatform.taskpool.normal",
"module-name": "entry_test"
},
"kits": [
{
"test-file-name": [
"ActsCrossplatformCommonlibraryTaskpoolTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', '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
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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'
export default function testsuite() {
TaskPoolTest()
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 List from '@ohos.util.List'
export default function TaskPoolTest() {
describe('TaskPoolTest', function () {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
function promiseCase() {
let p = new Promise<void>(function (resolve, reject) {
setTimeout(function () {
resolve()
}, 100)
}).then(undefined, (error) => {
})
return p
}
/**
* @tc.number : TEST_TASK_CONSTRUCTOR_001
* @tc.name : testTaskConstructor001
* @tc.desc : Create a Task instance. For example: let task = new taskpool.Task(function, args).
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskConstructor001', 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();
})
/**
* @tc.number : TEST_TASK_CONSTRUCTOR_002
* @tc.name : testTaskConstructor001
* @tc.desc : Create a Task instance. For example: let task = new taskpool.Task(function, args).
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskConstructor002', 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();
})
/**
* @tc.number : TEST_TASK_CONSTRUCTOR_003
* @tc.name : testTaskConstructor003
* @tc.desc : Create a Task instance. For example: let task = new taskpool.Task(function, args).
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskConstructor003', 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();
})
/**
* @tc.number : TEST_TASK_SET_TRANSFER_LIST_001
* @tc.name : testTaskSetTransferList001
* @tc.desc : To test Task SetTransferLis
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskSetTransferList001', 0, async function (done) {
let buffer = new ArrayBuffer(8);
let view = new Uint8Array(buffer);
let buffer1 = new ArrayBuffer(16);
let view1 = new Uint8Array(buffer1);
function testTransfer(arg1, arg2) {
"use concurrent"
return arg1.byteLength + arg2.byteLength;
}
let task = new taskpool.Task(testTransfer, view, view1);
task.setTransferList([view.buffer, view1.buffer]);
taskpool.execute(task).then((res)=>{
expect(res).assertEqual(24);
});
done();
})
/**
* @tc.number : TEST_TASK_GROUP_CONSTRUCTOR_001
* @tc.name : testTaskGroupConstructor001
* @tc.desc : Create a TaskGroup instance
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskGroupConstructor001', 0, async function (done) {
try {
let taskgroup = new taskpool.TaskGroup();
expect(taskgroup != undefined).assertEqual(true);
done();
} catch (err) {
expect(err.name).assertEqual("TypeError");
expect(err.code).assertEqual(undefined);
expect(err.message).assertEqual("Constructor is false");
}
})
/**
* @tc.number : TEST_TASK_GROUP_ADD_TASK_001
* @tc.name : testTaskGroupAddTask001
* @tc.desc : To test TaskGroup function addTask
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskGroupAddTask001', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
let task1 = new taskpool.Task(Sum,10,20);
let task2 = new taskpool.Task(Sum,10,20);
let task3 = new taskpool.Task(Sum,10,20);
let taskgroup = new taskpool.TaskGroup();
taskgroup.addTask(task1);
taskgroup.addTask(task2);
taskgroup.addTask(task3);
done();
})
/**
* @tc.number : TEST_TASK_GROUP_ADD_TASK_002
* @tc.name : testTaskGroupAddTask002
* @tc.desc : To test TaskGroup function addTask
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskGroupAddTask002', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
let taskgroup = new taskpool.TaskGroup();
taskgroup.addTask(Sum,10,20);
done();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_001
* @tc.name : testTaskPoolExecute001
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute001', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_002
* @tc.name : testTaskPoolExecute002
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute002', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_003
* @tc.name : testTaskPoolExecute003
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute003', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_004
* @tc.name : testTaskPoolExecute004
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute004', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_005
* @tc.name : testTaskPoolExecute002
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute005', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_006
* @tc.name : testTaskPoolExecute006
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute006', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_007
* @tc.name : testTaskPoolExecute007
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute007', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_008
* @tc.name : testTaskPoolExecute008
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute008', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_009
* @tc.name : testTaskPoolExecute009
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute009', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_010
* @tc.name : testTaskPoolExecute010
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute010', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_011
* @tc.name : testTaskPoolExecute011
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute011', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_012
* @tc.name : testTaskPoolExecute012
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute012', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_013
* @tc.name : testTaskPoolExecute013
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute013', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_014
* @tc.name : testTaskPoolExecute014
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute014', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_015
* @tc.name : testTaskPoolExecute015
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute015', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_016
* @tc.name : testTaskPoolExecute016
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute016', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_017
* @tc.name : testTaskPoolExecute017
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute017', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_018
* @tc.name : testTaskPoolExecute018
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute018', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_019
* @tc.name : testTaskPoolExecute019
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute019', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_020
* @tc.name : testTaskPoolExecute020
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute020', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_021
* @tc.name : testTaskPoolExecute021
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute021', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_022
* @tc.name : testTaskPoolExecute022
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute022', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_023
* @tc.name : testTaskPoolExecute023
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute023', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_024
* @tc.name : testTaskPoolExecute024
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute024', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_025
* @tc.name : testTaskPoolExecute025
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute025', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_026
* @tc.name : testTaskPoolExecute026
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute026', 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 isTerminate = false;
var result;
taskpool.execute(task).then((ret) => {
isTerminate = true;
result = ret;
});
while (!isTerminate) {
await promiseCase();
}
expect(result).assertEqual(true);
done();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_027
* @tc.name : testTaskPoolExecute027
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute027', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_028
* @tc.name : testTaskPoolExecute028
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute028', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_029
* @tc.name : testTaskPoolExecute029
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute029', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_030
* @tc.name : testTaskPoolExecute030
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute030', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_031
* @tc.name : testTaskPoolExecute031
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_032
* @tc.name : testTaskPoolExecute032
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute032', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_033
* @tc.name : testTaskPoolExecute033
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute033', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_034
* @tc.name : testTaskPoolExecute034
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute034', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_035
* @tc.name : testTaskPoolExecute035
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute035', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_036
* @tc.name : testTaskPoolExecute036
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute036', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_037
* @tc.name : testTaskPoolExecute037
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute037', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_038
* @tc.name : testTaskPoolExecute038
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute038', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_039
* @tc.name : testTaskPoolExecute039
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute039', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_040
* @tc.name : testTaskPoolExecute040
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute040', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_041
* @tc.name : testTaskPoolExecute041
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute041', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_042
* @tc.name : testTaskPoolExecute042
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute042', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_043
* @tc.name : testTaskPoolExecute043
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute043', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_044
* @tc.name : testTaskPoolExecute044
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute044', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_045
* @tc.name : testTaskPoolExecute045
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute045', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_046
* @tc.name : testTaskPoolExecute046
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute046', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_047
* @tc.name : testTaskPoolExecute047
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute047', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_048
* @tc.name : testTaskPoolExecute048
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute048', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_049
* @tc.name : testTaskPoolExecute049
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute049', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_050
* @tc.name : testTaskPoolExecute050
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute050', 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();
})
/**
* @tc.number : TEST_TASK_POOL_EXECUTE_051
* @tc.name : testTaskPoolExecute051
* @tc.desc : Place the pending function into the taskpool internal task queue and wait for the thread to execute.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolExecute051', 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 : TEST_TASK_POOL_Cancel_001
* @tc.name : testTaskPoolCancel001
* @tc.desc : Cancel tasks that have not been executed
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolCancel001', 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 : TEST_TASK_POOL_Cancel_002
* @tc.name : testTaskPoolCancel002
* @tc.desc : Cancel the task in progress
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolCancel002', 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 : TEST_TASK_POOL_Cancel_003
* @tc.name : testTaskPoolCancel003
* @tc.desc : Cancel the executed task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolCancel003', 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 : TEST_TASK_POOL_Cancel_004
* @tc.name : testTaskPoolCancel004
* @tc.desc : Cancel nonexistent task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolCancel004', 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 : TEST_TASK_POOL_Cancel_005
* @tc.name : testTaskPoolCancel005
* @tc.desc : Canceling unexecuted tasks multiple times
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolCancel005', 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 : TEST_TASK_POOL_Cancel_006
* @tc.name : testTaskPoolCancel006
* @tc.desc : Cancel all tasks in sequence
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('testTaskPoolCancel006', 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();
})
})
}
\ No newline at end of file
{
"module": {
"name": "entry_test",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册