提交 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"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
...@@ -16,6 +16,7 @@ group("commonlibrary") { ...@@ -16,6 +16,7 @@ group("commonlibrary") {
testonly = true testonly = true
if (is_standard_system) { if (is_standard_system) {
deps = [ deps = [
"crossplatform:crossplatform",
"ets_utils:ets_utils", "ets_utils:ets_utils",
"toolchain:toolchain", "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
{
"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.
先完成此消息的编辑!
想要评论请 注册