提交 77665827 编写于 作者: H hu0475

完成ability子系统context模块的跨平台测试套

Signed-off-by: Nhu0475 <huyanqiang5@huawei.com>
上级 19172b16
...@@ -17,6 +17,7 @@ group("ability") { ...@@ -17,6 +17,7 @@ group("ability") {
testonly = true testonly = true
if (is_standard_system) { if (is_standard_system) {
deps = [ deps = [
"crossplatform:ability_crossplatform",
"ability_runtime:ability_runtime", "ability_runtime:ability_runtime",
"dmsfwk:dmsfwk", "dmsfwk:dmsfwk",
] ]
......
# 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("//build/ohos_var.gni")
group("ability_crossplatform") {
testonly = true
if (is_standard_system) {
deps = [
"ability_runtime:ability_crossplatform_runtime",
]
}
}
# 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("//build/ohos_var.gni")
group("ability_crossplatform_runtime") {
testonly = true
if (is_standard_system) {
deps = [
"actscontexttest:context_ets_normal_test",
"actscontexttestentry:context_entry_ets_normal_test"
]
}
}
{
"app": {
"bundleName": "com.example.contexttest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"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("context_ets_normal_test") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsAbilityContextTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
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"
}
\ No newline at end of file
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "300000",
"shell-timeout": "300000",
"bundle-name": "com.example.contexttest",
"module-name": "entryTest",
"testcase-timeout": 5000
},
"kits": [
{
"test-file-name": [
"ActsAbilityContextTest.hap",
"ActsAbilityContextEntryTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
globalThis.stageContext = this.context;
}
}
\ 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 Ability from '@ohos.app.ability.UIAbility'
let abilityName = null;
function recordLife(ownList, abilityName, lifeName) {
ownList.push(abilityName + ' ' + lifeName);
}
export default class MainAbility1 extends Ability {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility1 onCreate")
abilityName = want.abilityName;
globalThis.list1 = [];
globalThis.parameters = null;
recordLife(globalThis.list1, abilityName, 'onCreate');
if (want.parameters) {
globalThis.parameters = want.parameters;
}
}
onDestroy() {
console.log("[Demo] MainAbility1 onDestroy")
recordLife(globalThis.list1, abilityName, 'onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility1 onWindowStageCreate")
globalThis.ability1Context = this.context;
windowStage.loadContent('TestAbility/pages/Index1', (err, data) => {
if (err.code) {
console.log('MainAbility1 loadContent error');
return;
}
console.log('MainAbility1 loadContent success');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility1 onWindowStageDestroy")
}
onForeground() {
console.log("[Demo] MainAbility1 onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility1 onBackground")
}
};
/*
* 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) ?? '');
});
globalThis.abilityContext = this.context;
globalThis.colorMode = this.context.config.colorMode;
globalThis.direction = this.context.config.direction;
}
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
/*
* 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.
*/
@Entry
@Component
struct Index1 {
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World Mainability1')
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.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 Common from './actsCommonTest/Common.test';
import Configuration from './actsConfigurationTest/Configuration.test';
import AbilityStageContext from './actsAbilityStageContextTest/AbilityStageContext.test';
import ApplicationContext from './actsApplicationContextTest/ApplicationContext.test';
import UIAbilityContext from './actsUIAbilityContextTest/UIAbilityContext.test';
export default function testsuite() {
Common();
Configuration();
AbilityStageContext();
ApplicationContext();
UIAbilityContext();
}
/*
* 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 common from '@ohos.app.ability.common';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function AbilityStageContext() {
describe("AbilityStageContext", function () {
let bundleName: any;
beforeAll(async function () {
console.info("beforeAll case");
});
beforeEach(async function () {
console.info("beforeEach case");
});
afterEach(async function () {
console.info('afterEach case');
});
afterAll(async function () {
console.info("afterAll case");
});
/**
* @tc.number : ABILITY_TEST_ABILITYSTAGECONTEXT_CURRENTHAPMODULEINFO_0100
* @tc.name : testAbilityStageContextCurrentHapModuleInfo001
* @tc.desc : test filed of currentHapModuleInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testAbilityStageContextCurrentHapModuleInfo001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
expect(context != null).assertTrue();
let hapModuleInfo = context.currentHapModuleInfo;
expect(hapModuleInfo != null).assertTrue();
console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.name: ` + hapModuleInfo.name);
expect(hapModuleInfo.name == "entryTest").assertTrue();
console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.icon: ` + hapModuleInfo.icon);
expect(hapModuleInfo.icon == "$media:icon").assertTrue();
console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.iconId: ` + hapModuleInfo.iconId);
expect(typeof (hapModuleInfo.iconId) == 'number').assertTrue();
console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.label: ` + hapModuleInfo.label);
expect(hapModuleInfo.label == "$string:TestAbility_label").assertTrue();
console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.labelId: ` + hapModuleInfo.labelId);
expect(typeof (hapModuleInfo.labelId) == 'number').assertTrue();
console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.description: ` + hapModuleInfo.description);
expect(hapModuleInfo.description == "$string:module_test_desc").assertTrue();
console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.descriptionId: ` + hapModuleInfo.descriptionId);
expect(typeof (hapModuleInfo.descriptionId) == 'number').assertTrue();
console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.mainElementName: ` + hapModuleInfo.mainElementName);
expect(hapModuleInfo.mainElementName == "TestAbility").assertTrue();
console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.metadata: ` + hapModuleInfo.metadata.length);
expect(hapModuleInfo.metadata.length >= 0).assertTrue();
console.log(`testAbilityStageContextCurrentHapModuleInfo001 success`);
done();
} catch (err) {
console.log(`testAbilityStageContextCurrentHapModuleInfo001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_ABILITYSTAGECONTEXT_CONFIG_0100
* @tc.name : testAbilityStageContextConfig001
* @tc.desc : test filed of config
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testAbilityStageContextConfig001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
expect(context != null).assertTrue();
let config = context.config;
expect(config != null).assertTrue();
console.log(`testAbilityStageContextConfig001 config.colorMode: ` + config.colorMode);
expect(typeof (config.colorMode) == 'number').assertTrue();
console.log(`testAbilityStageContextConfig001 config.direction: ` + config.direction);
expect(typeof (config.direction) == 'number').assertTrue();
console.log(`testAbilityStageContextConfig001 success`);
done();
} catch (err) {
console.log(`testAbilityStageContextConfig001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STAGEMODE_0100
* @tc.name : testStageMode001
* @tc.desc : test filed of stageMode
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testStageMode001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
expect(context.stageMode).assertTrue();
console.log(`testStageMode001 success`);
done();
} catch (err) {
console.log(`testStageMode001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_RESOURCEMANAGER_0100
* @tc.name : testResourceManager001
* @tc.desc : test filed of resourceManager
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testResourceManager001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
expect(context.resourceManager != null).assertTrue();
console.log(`testResourceManager001 success`);
done();
} catch (err) {
console.log(`testResourceManager001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_APPLICATIONINFO_0100
* @tc.name : testApplicationInfo001
* @tc.desc : test filed of applicationInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testApplicationInfo001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
expect(context != null).assertTrue();
let applicationInfo = context.applicationInfo;
expect(applicationInfo != null).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.name: ` + applicationInfo.name);
expect(applicationInfo.name == 'com.example.contexttest').assertTrue();
console.log(`testApplicationInfo001 applicationInfo.description: ` + applicationInfo.description.length);
expect(applicationInfo.description.length >= 0).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.descriptionId: ` + applicationInfo.descriptionId);
expect(applicationInfo.descriptionId == 0).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.label: ` + applicationInfo.label);
expect(applicationInfo.label == '$string:app_name').assertTrue();
console.log(`testApplicationInfo001 applicationInfo.labelId: ` + applicationInfo.labelId);
expect(applicationInfo.labelId != null).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.icon: ` + applicationInfo.icon);
expect(applicationInfo.icon == '$media:app_icon').assertTrue();
console.log(`testApplicationInfo001 applicationInfo.iconId: ` + applicationInfo.iconId);
expect(applicationInfo.iconId != null).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.codePath: ` + applicationInfo.codePath);
expect(typeof (applicationInfo.codePath) == 'string').assertTrue();
console.log(`testApplicationInfo001 success`);
done();
} catch (err) {
console.log(`testApplicationInfo001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CACHEDIR_0100
* @tc.name : testCacheDir001
* @tc.desc : test filed of cacheDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testCacheDir001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
console.log(`testCacheDir001 cacheDir:` + context.cacheDir);
expect(typeof (context.cacheDir) == 'string').assertTrue();
console.log(`testCacheDir001 success`);
done();
} catch (err) {
console.log(`testCacheDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_TEMPDIR_0100
* @tc.name : testTempDir001
* @tc.desc : test filed of tempDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testTempDir001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
console.log(`testTempDir001 tempDir:` + context.tempDir);
expect(typeof (context.tempDir) == 'string').assertTrue();
console.log(`testTempDir001 success`);
done();
} catch (err) {
console.log(`testTempDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_FILESDIR_0100
* @tc.name : testFilesDir001
* @tc.desc : test filed of filesDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testFilesDir001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
console.log(`testFilesDir001 filesDir:` + context.filesDir);
expect(typeof (context.filesDir) == 'string').assertTrue();
console.log(`testFilesDir001 success`);
done();
} catch (err) {
console.log(`testFilesDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_DATABASEDIR_0100
* @tc.name : testDatabaseDir001
* @tc.desc : test filed of databaseDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testDatabaseDir001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
console.log(`testDatabaseDir001 databaseDir:` + context.databaseDir);
expect(typeof (context.databaseDir) == 'string').assertTrue();
console.log(`testDatabaseDir001 success`);
done();
} catch (err) {
console.log(`testDatabaseDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_PREFERENCESDIR_0100
* @tc.name : testPreferencesDir001
* @tc.desc : test filed of preferencesDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testPreferencesDir001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
console.log(`testPreferencesDir001 preferencesDir:` + context.preferencesDir);
expect(typeof (context.preferencesDir) == 'string').assertTrue();
console.log(`testPreferencesDir001 success`);
done();
} catch (err) {
console.log(`testPreferencesDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_BUNDLECODEDIR_0100
* @tc.name : testBundleCodeDir001
* @tc.desc : test filed of bundleCodeDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testBundleCodeDir001', 0, async function (done) {
try {
let context: common.AbilityStageContext = globalThis.stageContext;
console.log(`testBundleCodeDir001 bundleCodeDir:` + context.bundleCodeDir);
expect(typeof (context.bundleCodeDir) == 'string').assertTrue();
console.log(`testBundleCodeDir001 success`);
done();
} catch (err) {
console.log(`testBundleCodeDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0100
* @tc.name : testCreateModuleContext001
* @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap1
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext001", 0, async function (done) {
try {
console.info("testCreateModuleContext001 begin");
let context: common.AbilityStageContext = globalThis.stageContext;
expect(context != null).assertTrue();
let moduleContext = context.createModuleContext("entry");
expect(moduleContext != null).assertTrue();
bundleName = moduleContext.applicationInfo.name;
console.info("testCreateModuleContext001 bundleName: " + bundleName);
expect(bundleName).assertEqual("com.example.contexttest");
done();
} catch (err) {
console.info("testCreateModuleContext001 err: " + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0200
* @tc.name : testCreateModuleContext002
* @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap2
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext002", 0, async function (done) {
try {
console.log("testCreateModuleContext002 begin");
let context: common.AbilityStageContext = globalThis.stageContext;
expect(context != null).assertTrue();
let moduleContext = context.createModuleContext("entryTest");
expect(moduleContext != null).assertTrue();
bundleName = moduleContext.applicationInfo.name;
console.info("testCreateModuleContext002 bundleName: " + bundleName);
expect(bundleName).assertEqual("com.example.contexttest");
done();
} catch (err) {
console.info("testCreateModuleContext002 err: " + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0300
* @tc.name : testCreateModuleContext003
* @tc.desc : Context calls createModuleContext, passing in the moduleName of the cross-application hap1
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext003", 0, async function (done) {
try {
console.info("testCreateModuleContext003 begin");
let context: common.AbilityStageContext = globalThis.stageContext;
let moduleContext = context.createModuleContext("entry_assist");
expect(!moduleContext).assertTrue();
done();
} catch (err) {
let e = err.toString();
let errLog = "Invalid input parameter"
console.debug("testCreateModuleContext003 ====>e====>" + e);
expect(e.indexOf(errLog) >= 0).assertTrue();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0400
* @tc.name : testCreateModuleContext004
* @tc.desc : Context calls createModuleContext, passing in a non-existing moduleName
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext004", 0, async function (done) {
try {
console.info("testCreateModuleContext004 begin");
let context: common.AbilityStageContext = globalThis.stageContext;
let moduleContext = context.createModuleContext("abc");
expect(!moduleContext).assertTrue();
done();
} catch (err) {
let e = err.toString();
let errLog = "Invalid input parameter"
console.debug("testCreateModuleContext004 ====>e====>" + e);
expect(e.indexOf(errLog) >= 0).assertTrue();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0500
* @tc.name : testCreateModuleContext005
* @tc.desc : Context calls createModuleContext, and the incoming moduleName is undefined
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext005", 0, async function (done) {
try {
console.info("testCreateModuleContext005 begin");
let context: common.AbilityStageContext = globalThis.stageContext;
let moduleContext = context.createModuleContext(undefined);
expect(moduleContext != null).assertTrue();
done();
} catch (err) {
let e = err.toString();
let errLog = "Invalid input parameter"
console.debug("testCreateModuleContext005 ====>e====>" + e);
expect(e.indexOf(errLog) >= 0).assertTrue();
done();
}
})
/**
* @tc.number : ABILITY_TEST_GETAPPLICATIONCONTEXT_0100
* @tc.name : testGetApplicationContext001
* @tc.desc : test getApplicationContext return not empty
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testGetApplicationContext001", 0, async function (done) {
try {
console.info("testGetApplicationContext001 begin");
let context: common.AbilityStageContext = globalThis.stageContext;
let applicationContext = context.getApplicationContext();
expect(applicationContext != null).assertTrue();
console.info("testGetApplicationContext001 success");
done();
} catch (err) {
console.log(`testGetApplicationContext001 fail: ` + err);
expect().assertFail();
done();
}
});
})
}
/*
* 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 common from '@ohos.app.ability.common';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function ApplicationContext() {
describe("ApplicationContext", function () {
let bundleName: any;
beforeAll(async function () {
console.info("beforeAll case");
});
beforeEach(async function () {
console.info("beforeEach case");
});
afterEach(async function () {
console.info('afterEach case');
});
afterAll(async function () {
console.info("afterAll case");
});
/**
* @tc.number : ABILITY_TEST_GETRUNNINGPROCESSINFORMATION_PROMISE_0100
* @tc.name : testGetRunningProcessInformationPromise001
* @tc.desc : test getRunningProcessInformation(promise)
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testGetRunningProcessInformationPromise001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let appContext: common.ApplicationContext = abilityContext.getApplicationContext();
expect(appContext != null).assertTrue();
appContext.getRunningProcessInformation().then((data) => {
expect(data != undefined).assertTrue();
console.log(`testGetRunningProcessInformationPromise001 pid:` + data[0].pid);
expect(data[0].pid > 0).assertTrue();
console.log(`testGetRunningProcessInformationPromise001 processName:` + data[0].processName);
expect(data[0].processName == "com.example.contexttest").assertTrue();
console.log(`testGetRunningProcessInformationPromise001 bundleNames:` + data[0].bundleNames);
expect(data[0].bundleNames[0] == "com.example.contexttest").assertTrue();
console.log(`testGetRunningProcessInformationPromise001 success`);
done();
}).catch((err) => {
console.log(`testGetRunningProcessInformationPromise001 fail ` + err);
expect().assertFail();
done();
})
} catch (err) {
console.log(`testGetRunningProcessInformationPromise001 fail ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_GETRUNNINGPROCESSINFORMATION_CALLBACK_0100
* @tc.name : testGetRunningProcessInformationCb001
* @tc.desc : test getRunningProcessInformation(callback)
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testGetRunningProcessInformationCb001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let appContext: common.ApplicationContext = abilityContext.getApplicationContext();
expect(appContext != null).assertTrue();
appContext.getRunningProcessInformation((err, data) => {
expect(data != undefined).assertTrue();
console.log(`testGetRunningProcessInformationCb001 pid:` + data[0].pid);
expect(data[0].pid > 0).assertTrue();
console.log(`testGetRunningProcessInformationCb001 processName:` + data[0].processName);
expect(data[0].processName == "com.example.contexttest").assertTrue();
console.log(`testGetRunningProcessInformationCb001 bundleNames:` + data[0].bundleNames);
expect(data[0].bundleNames[0] == "com.example.contexttest").assertTrue();
console.log(`testGetRunningProcessInformationCb001 success`);
done();
})
} catch (err) {
console.log(`testGetRunningProcessInformationCb001 fail ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STAGEMODE_0100
* @tc.name : testStageMode001
* @tc.desc : test filed of stageMode
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testStageMode001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
expect(context.stageMode).assertTrue();
console.log(`testStageMode001 success`);
done();
} catch (err) {
console.log(`testStageMode001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_RESOURCEMANAGER_0100
* @tc.name : testResourceManager001
* @tc.desc : test filed of resourceManager
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testResourceManager001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
expect(context.resourceManager != null).assertTrue();
console.log(`testResourceManager001 success`);
done();
} catch (err) {
console.log(`testResourceManager001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_APPLICATIONINFO_0100
* @tc.name : testApplicationInfo001
* @tc.desc : test filed of applicationInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testApplicationInfo001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
expect(context != null).assertTrue();
let applicationInfo = context.applicationInfo;
expect(applicationInfo != null).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.name: ` + applicationInfo.name);
expect(applicationInfo.name == 'com.example.contexttest').assertTrue();
console.log(`testApplicationInfo001 applicationInfo.description: ` + applicationInfo.description.length);
expect(applicationInfo.description.length >= 0).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.descriptionId: ` + applicationInfo.descriptionId);
expect(applicationInfo.descriptionId == 0).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.label: ` + applicationInfo.label);
expect(applicationInfo.label == '$string:app_name').assertTrue();
console.log(`testApplicationInfo001 applicationInfo.labelId: ` + applicationInfo.labelId);
expect(applicationInfo.labelId != null).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.icon: ` + applicationInfo.icon);
expect(applicationInfo.icon == '$media:app_icon').assertTrue();
console.log(`testApplicationInfo001 applicationInfo.iconId: ` + applicationInfo.iconId);
expect(applicationInfo.iconId != null).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.codePath: ` + applicationInfo.codePath);
expect(typeof (applicationInfo.codePath) == 'string').assertTrue();
console.log(`testApplicationInfo001 success`);
done();
} catch (err) {
console.log(`testApplicationInfo001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CACHEDIR_0100
* @tc.name : testCacheDir001
* @tc.desc : test filed of cacheDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testCacheDir001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
console.log(`testCacheDir001 cacheDir:` + context.cacheDir);
expect(typeof (context.cacheDir) == 'string').assertTrue();
console.log(`testCacheDir001 success`);
done();
} catch (err) {
console.log(`testCacheDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_TEMPDIR_0100
* @tc.name : testTempDir001
* @tc.desc : test filed of tempDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testTempDir001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
console.log(`testTempDir001 tempDir:` + context.tempDir);
expect(typeof (context.tempDir) == 'string').assertTrue();
console.log(`testTempDir001 success`);
done();
} catch (err) {
console.log(`testTempDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_FILESDIR_0100
* @tc.name : testFilesDir001
* @tc.desc : test filed of filesDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testFilesDir001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
console.log(`testFilesDir001 filesDir:` + context.filesDir);
expect(typeof (context.filesDir) == 'string').assertTrue();
console.log(`testFilesDir001 success`);
done();
} catch (err) {
console.log(`testFilesDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_DATABASEDIR_0100
* @tc.name : testDatabaseDir001
* @tc.desc : test filed of databaseDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testDatabaseDir001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
console.log(`testDatabaseDir001 databaseDir:` + context.databaseDir);
expect(typeof (context.databaseDir) == 'string').assertTrue();
console.log(`testDatabaseDir001 success`);
done();
} catch (err) {
console.log(`testDatabaseDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_PREFERENCESDIR_0100
* @tc.name : testPreferencesDir001
* @tc.desc : test filed of preferencesDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testPreferencesDir001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
console.log(`testPreferencesDir001 preferencesDir:` + context.preferencesDir);
expect(typeof (context.preferencesDir) == 'string').assertTrue();
console.log(`testPreferencesDir001 success`);
done();
} catch (err) {
console.log(`testPreferencesDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_BUNDLECODEDIR_0100
* @tc.name : testBundleCodeDir001
* @tc.desc : test filed of bundleCodeDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testBundleCodeDir001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
console.log(`testBundleCodeDir001 bundleCodeDir:` + context.bundleCodeDir);
expect(typeof (context.bundleCodeDir) == 'string').assertTrue();
console.log(`testBundleCodeDir001 success`);
done();
} catch (err) {
console.log(`testBundleCodeDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0100
* @tc.name : testCreateModuleContext001
* @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap1
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext001", 0, async function (done) {
try {
console.info("testCreateModuleContext001 begin");
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
expect(context != null).assertTrue();
let moduleContext = context.createModuleContext("entry");
expect(moduleContext != null).assertTrue();
bundleName = moduleContext.applicationInfo.name;
console.info("testCreateModuleContext001 bundleName: " + bundleName);
expect(bundleName).assertEqual("com.example.contexttest");
done();
} catch (err) {
console.info("testCreateModuleContext001 err: " + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0200
* @tc.name : testCreateModuleContext002
* @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap2
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext002", 0, async function (done) {
try {
console.log("testCreateModuleContext002 begin");
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
expect(context != null).assertTrue();
let moduleContext = context.createModuleContext("entryTest");
expect(moduleContext != null).assertTrue();
bundleName = moduleContext.applicationInfo.name;
console.info("testCreateModuleContext002 bundleName: " + bundleName);
expect(bundleName).assertEqual("com.example.contexttest");
done();
} catch (err) {
console.info("testCreateModuleContext002 err: " + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0300
* @tc.name : testCreateModuleContext003
* @tc.desc : Context calls createModuleContext, passing in the moduleName of the cross-application hap1
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext003", 0, async function (done) {
try {
console.info("testCreateModuleContext003 begin");
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
let moduleContext = context.createModuleContext("entry_assist");
expect(!moduleContext).assertTrue();
done();
} catch (err) {
let e = err.toString();
let errLog = "Invalid input parameter"
console.debug("testCreateModuleContext003 ====>e====>" + e);
expect(e.indexOf(errLog) >= 0).assertTrue();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0400
* @tc.name : testCreateModuleContext004
* @tc.desc : Context calls createModuleContext, passing in a non-existing moduleName
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext004", 0, async function (done) {
try {
console.info("testCreateModuleContext004 begin");
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
let moduleContext = context.createModuleContext("abc");
expect(!moduleContext).assertTrue();
done();
} catch (err) {
let e = err.toString();
let errLog = "Invalid input parameter"
console.debug("testCreateModuleContext004 ====>e====>" + e);
expect(e.indexOf(errLog) >= 0).assertTrue();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0500
* @tc.name : testCreateModuleContext005
* @tc.desc : Context calls createModuleContext, and the incoming moduleName is undefined
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext005", 0, async function (done) {
try {
console.info("testCreateModuleContext005 begin");
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
let moduleContext = context.createModuleContext(undefined);
expect(moduleContext != null).assertTrue();
done();
} catch (err) {
let e = err.toString();
let errLog = "Invalid input parameter"
console.debug("testCreateModuleContext005 ====>e====>" + e);
expect(e.indexOf(errLog) >= 0).assertTrue();
done();
}
})
/**
* @tc.number : ABILITY_TEST_GETAPPLICATIONCONTEXT_0100
* @tc.name : testGetApplicationContext001
* @tc.desc : test getApplicationContext return not empty
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testGetApplicationContext001", 0, async function (done) {
try {
console.info("testGetApplicationContext001 begin");
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let context: common.ApplicationContext = abilityContext.getApplicationContext();
let applicationContext = context.getApplicationContext();
expect(applicationContext != null).assertTrue();
console.info("testGetApplicationContext001 success");
done();
} catch (err) {
console.log(`testGetApplicationContext001 fail: ` + err);
expect().assertFail();
done();
}
});
})
}
/*
* 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 common from '@ohos.app.ability.common';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function Common() {
describe("Common", function () {
beforeAll(async function () {
console.info("beforeAll case");
});
beforeEach(async function () {
console.info("beforeEach case");
});
afterEach(async function () {
console.info('afterEach case');
});
afterAll(async function () {
console.info("afterAll case");
});
/**
* @tc.number : ABILITY_TEST_COMMON_0100
* @tc.name : testCommon001
* @tc.desc : test Common of UIAbilityContext
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testCommon001', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
console.log(`testCommon001 success`);
done();
} catch (err) {
console.log(`testCommon001 fail:` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_COMMON_0200
* @tc.name : testCommon002
* @tc.desc : test Common of AbilityStageContext
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testCommon002', 0, async function (done) {
try {
let stageContext: common.AbilityStageContext = globalThis.stageContext;
expect(stageContext != null).assertTrue();
console.log(`testCommon002 success`);
done();
} catch (err) {
console.log(`testCommon002 fail:` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_COMMON_0300
* @tc.name : testCommon003
* @tc.desc : test Common of ApplicationContext
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testCommon003', 0, async function (done) {
try {
let abilityContext: common.UIAbilityContext = globalThis.abilityContext;
expect(abilityContext != null).assertTrue();
let appContext: common.ApplicationContext = abilityContext.getApplicationContext();
expect(appContext != null).assertTrue();
console.log(`testCommon003 success`);
done();
} catch (err) {
console.log(`testCommon003 fail:` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_COMMON_0400
* @tc.name : testCommon004
* @tc.desc : test Common of BaseContext
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testCommon004', 0, async function (done) {
try {
let stageContext: common.AbilityStageContext = globalThis.stageContext;
expect(stageContext != null).assertTrue();
let baseContext: common.BaseContext = stageContext;
expect(baseContext != null).assertTrue();
console.log(`testCommon004 success`);
done();
} catch (err) {
console.log(`testCommon004 fail:` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_COMMON_0500
* @tc.name : testCommon005
* @tc.desc : test Common of Context
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testCommon005', 0, async function (done) {
try {
let stageContext: common.AbilityStageContext = globalThis.stageContext;
expect(stageContext != null).assertTrue();
let context: common.Context = stageContext;
expect(context != null).assertTrue();
console.log(`testCommon005 success`);
done();
} catch (err) {
console.log(`testCommon005 fail:` + err);
expect().assertFail();
done();
}
})
})
}
/*
* 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 common from '@ohos.app.ability.common';
import configurationConstant from '@ohos.app.ability.ConfigurationConstant';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function Configuration() {
describe("Configuration", function () {
beforeAll(async function () {
console.info("beforeAll case");
});
beforeEach(async function () {
console.info("beforeEach case");
});
afterEach(async function () {
console.info('afterEach case');
});
afterAll(async function () {
console.info("afterAll case");
});
/**
* @tc.number : ABILITY_TEST_COLORMODE_0100
* @tc.name : testColorMode001
* @tc.desc : test filed of colorMode
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testColorMode001', 0, async function (done) {
try {
let colorMode = globalThis.colorMode;
let context: common.UIAbilityContext = globalThis.abilityContext;
console.log(`testColorMode001 colorMode:` + colorMode);
if (colorMode == configurationConstant.ColorMode.COLOR_MODE_NOT_SET) {
expect(context.config.colorMode).assertEqual(configurationConstant.ColorMode.COLOR_MODE_NOT_SET);
} else if (colorMode == configurationConstant.ColorMode.COLOR_MODE_DARK) {
expect(context.config.colorMode).assertEqual(configurationConstant.ColorMode.COLOR_MODE_DARK);
expect(context.config.colorMode != configurationConstant.ColorMode.COLOR_MODE_NOT_SET).assertTrue();
expect(context.config.colorMode != configurationConstant.ColorMode.COLOR_MODE_LIGHT).assertTrue();
} else if (colorMode == configurationConstant.ColorMode.COLOR_MODE_LIGHT) {
expect(context.config.colorMode).assertEqual(configurationConstant.ColorMode.COLOR_MODE_LIGHT);
expect(context.config.colorMode != configurationConstant.ColorMode.COLOR_MODE_NOT_SET).assertTrue();
expect(context.config.colorMode != configurationConstant.ColorMode.COLOR_MODE_DARK).assertTrue();
}
console.log(`testColorMode001 success`);
done();
} catch (err) {
console.log(`testColorMode001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_DIRECTION_0100
* @tc.name : testDirection001
* @tc.desc : test filed of direction
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testDirection001', 0, async function (done) {
try {
let direction = globalThis.direction;
let context: common.UIAbilityContext = globalThis.abilityContext;
console.log(`testDirection001 direction:` + direction);
if (direction == configurationConstant.Direction.DIRECTION_NOT_SET) {
expect(context.config.direction).assertEqual(configurationConstant.Direction.DIRECTION_NOT_SET);
} else if (direction == configurationConstant.Direction.DIRECTION_VERTICAL) {
expect(context.config.direction).assertEqual(configurationConstant.Direction.DIRECTION_VERTICAL);
expect(context.config.direction != configurationConstant.Direction.DIRECTION_NOT_SET).assertTrue();
expect(context.config.direction != configurationConstant.Direction.DIRECTION_HORIZONTAL).assertTrue();
} else if (direction == configurationConstant.Direction.DIRECTION_HORIZONTAL) {
expect(context.config.direction).assertEqual(configurationConstant.Direction.DIRECTION_HORIZONTAL);
expect(context.config.direction != configurationConstant.Direction.DIRECTION_NOT_SET).assertTrue();
expect(context.config.direction != configurationConstant.Direction.DIRECTION_VERTICAL).assertTrue();
}
console.log(`testDirection001 success`);
done();
} catch (err) {
console.log(`testDirection001 fail: ` + err);
expect().assertFail();
done();
}
})
})
}
/*
* 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 common from '@ohos.app.ability.common';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function UIAbilityContext() {
describe("UIAbilityContext", function () {
let bundleName: any;
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time))
}
beforeAll(async function () {
console.info("beforeAll case");
});
beforeEach(async function () {
console.info("beforeEach case");
});
afterEach(async function () {
console.info('afterEach case');
});
afterAll(async function () {
console.info("afterAll case");
});
/**
* @tc.number : ABILITY_TEST_ABILITYINFO_0100
* @tc.name : testAbilityInfo001
* @tc.desc : test AbilityInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testAbilityInfo001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
let abilityInfo = context.abilityInfo;
expect(abilityInfo != null).assertTrue();
console.log(`testAbilityInfo001 abilityInfo.bundleName: ` + abilityInfo.bundleName);
expect(abilityInfo.bundleName == "com.example.contexttest").assertTrue();
console.log(`testAbilityInfo001 abilityInfo.moduleName: ` + abilityInfo.moduleName);
expect(abilityInfo.moduleName == "entryTest").assertTrue();
console.log(`testAbilityInfo001 abilityInfo.name: ` + abilityInfo.name);
expect(abilityInfo.name == "TestAbility").assertTrue();
console.log(`testAbilityInfo001 abilityInfo.label: ` + abilityInfo.label);
expect(abilityInfo.label == "$string:TestAbility_label").assertTrue();
console.log(`testAbilityInfo001 abilityInfo.labelId: ` + abilityInfo.labelId);
expect(typeof (abilityInfo.labelId) == 'number').assertTrue();
console.log(`testAbilityInfo001 abilityInfo.description: ` + abilityInfo.description);
expect(abilityInfo.description == "$string:TestAbility_desc").assertTrue();
console.log(`testAbilityInfo001 abilityInfo.descriptionId: ` + abilityInfo.descriptionId);
expect(typeof (abilityInfo.descriptionId) == 'number').assertTrue();
console.log(`testAbilityInfo001 abilityInfo.icon: ` + abilityInfo.icon);
expect(abilityInfo.icon == "$media:icon").assertTrue();
console.log(`testAbilityInfo001 abilityInfo.iconId: ` + abilityInfo.iconId);
expect(typeof (abilityInfo.iconId) == 'number').assertTrue();
console.log(`testAbilityInfo001 abilityInfo.applicationInfo: ` + abilityInfo.applicationInfo.name);
expect(abilityInfo.applicationInfo.name == "com.example.contexttest").assertTrue();
console.log(`testAbilityInfo001 abilityInfo.metadata: ` + abilityInfo.metadata.length);
expect(abilityInfo.metadata.length >= 0).assertTrue();
console.log(`testAbilityInfo001 success`);
done();
} catch (err) {
console.log(`testAbilityInfo001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_UIABILITYCONTEXT_CURRENTHAPMODULEINFO_0100
* @tc.name : testUIAbilityContextCurrentHapModuleInfo001
* @tc.desc : test filed of currentHapModuleInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testUIAbilityContextCurrentHapModuleInfo001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
let hapModuleInfo = context.currentHapModuleInfo;
expect(hapModuleInfo != null).assertTrue();
console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.name: ` + hapModuleInfo.name);
expect(hapModuleInfo.name == "entryTest").assertTrue();
console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.icon: ` + hapModuleInfo.icon);
expect(hapModuleInfo.icon == "$media:icon").assertTrue();
console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.iconId: ` + hapModuleInfo.iconId);
expect(typeof (hapModuleInfo.iconId) == 'number').assertTrue();
console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.label: ` + hapModuleInfo.label);
expect(hapModuleInfo.label == "$string:TestAbility_label").assertTrue();
console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.labelId: ` + hapModuleInfo.labelId);
expect(typeof (hapModuleInfo.labelId) == 'number').assertTrue();
console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.description: ` + hapModuleInfo.description);
expect(hapModuleInfo.description == "$string:module_test_desc").assertTrue();
console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.descriptionId: ` + hapModuleInfo.descriptionId);
expect(typeof (hapModuleInfo.descriptionId) == 'number').assertTrue();
console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.mainElementName: ` + hapModuleInfo.mainElementName);
expect(hapModuleInfo.mainElementName == "TestAbility").assertTrue();
console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.metadata: ` + hapModuleInfo.metadata.length);
expect(hapModuleInfo.metadata.length >= 0).assertTrue();
console.log(`testUIAbilityContextCurrentHapModuleInfo001 success`);
done();
} catch (err) {
console.log(`testUIAbilityContextCurrentHapModuleInfo001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_UIABILITYCONTEXT_CONFIG_0100
* @tc.name : testUIAbilityContextConfig001
* @tc.desc : test filed of config
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testUIAbilityContextConfig001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
let config = context.config;
expect(config != null).assertTrue();
console.log(`testUIAbilityContextConfig001 config.colorMode: ` + config.colorMode);
expect(typeof (config.colorMode) == 'number').assertTrue();
console.log(`testUIAbilityContextConfig001 config.direction: ` + config.direction);
expect(typeof (config.direction) == 'number').assertTrue();
console.log(`testUIAbilityContextConfig001 success`);
done();
} catch (err) {
console.log(`testUIAbilityContextConfig001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0100
* @tc.name : testStartAbilityPromise001
* @tc.desc : test startAbility right
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want).then(() => {
console.info('testStartAbilityPromise001 start successful.');
}).catch((error) => {
console.error('testStartAbilityPromise001 start failed. Cause: ' + JSON.stringify(error));
})
await sleep(1500);
const result = globalThis.list1;
console.info('result: ' + JSON.stringify(result));
expect(result[0]).assertEqual('MainAbility1 onCreate');
let context1: common.UIAbilityContext = globalThis.ability1Context;
context1.terminateSelf();
await sleep(1000);
console.log(`testStartAbilityPromise001 success`);
done();
} catch (err) {
console.log(`testStartAbilityPromise001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0200
* @tc.name : testStartAbilityPromise002
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise002', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
var want = {
"bundleName": "com.example.abc",
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want).then(() => {
console.log(`testStartAbilityPromise002 fail: `);
expect().assertFail();
done();
}).catch((error) => {
console.log(`testStartAbilityPromise002 error.code: ` + error.code);
expect(true).assertTrue();
done();
})
} catch (err) {
console.log(`testStartAbilityPromise002 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0300
* @tc.name : testStartAbilityPromise003
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise003', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
var want = {
"bundleName": " ",
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want).then(() => {
console.log(`testStartAbilityPromise003 fail: `);
expect().assertFail();
done();
}).catch((error) => {
console.log(`testStartAbilityPromise003 error.code: ` + error.code);
expect(true).assertTrue();
done();
})
} catch (err) {
console.log(`testStartAbilityPromise003 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0400
* @tc.name : testStartAbilityPromise004
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise004', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
var want = {
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want).then(() => {
console.log(`testStartAbilityPromise004 fail: `);
expect().assertFail();
done();
}).catch((error) => {
console.log(`testStartAbilityPromise004 error.code: ` + error.code);
expect(true).assertTrue();
done();
})
} catch (err) {
console.log(`testStartAbilityPromise004 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0500
* @tc.name : testStartAbilityPromise005
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise005', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": "abc"
}
context.startAbility(want).then(() => {
console.log(`testStartAbilityPromise005 fail: `);
expect().assertFail();
done();
}).catch((error) => {
console.log(`testStartAbilityPromise005 error.code: ` + error.code);
expect(true).assertTrue();
done();
})
} catch (err) {
console.log(`testStartAbilityPromise005 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0600
* @tc.name : testStartAbilityPromise006
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise006', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": " "
}
context.startAbility(want).then(() => {
console.log(`testStartAbilityPromise006 fail `);
expect().assertFail();
done();
}).catch((error) => {
console.log(`testStartAbilityPromise006 error.code: ` + error.code);
expect(true).assertTrue();
done();
})
} catch (err) {
console.log(`testStartAbilityPromise006 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0800
* @tc.name : testStartAbilityPromise008
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise008', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "abc",
"moduleName": "entryTest"
}
context.startAbility(want).then(() => {
console.log(`testStartAbilityPromise008 fail: `);
expect().assertFail();
done();
}).catch((error) => {
console.log(`testStartAbilityPromise008 error.code: ` + error.code);
expect(true).assertTrue();
done();
})
} catch (err) {
console.log(`testStartAbilityPromise008 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0900
* @tc.name : testStartAbilityPromise009
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise009', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
var want = {
"bundleName": "com.example.contexttest",
"abilityName": " ",
"moduleName": "entryTest"
}
context.startAbility(want).then(() => {
console.log(`testStartAbilityPromise009 fail: `);
expect().assertFail();
done();
}).catch((error) => {
console.log(`testStartAbilityPromise009 error.code: ` + error.code);
expect(true).assertTrue();
done();
})
} catch (err) {
console.log(`testStartAbilityPromise009 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_1000
* @tc.name : testStartAbilityPromise010
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise010', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
var want = {
"bundleName": "com.example.contexttest",
"moduleName": "entryTest"
}
context.startAbility(want).then(() => {
console.log(`testStartAbilityPromise010 fail: `);
expect().assertFail();
done();
}).catch((error) => {
console.log(`testStartAbilityPromise010 error.code: ` + error.code);
expect(true).assertTrue();
done();
})
} catch (err) {
console.log(`testStartAbilityPromise010 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_1100
* @tc.name : testStartAbilityPromise011
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise011', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
var want = {}
context.startAbility(want).then(() => {
console.log(`testStartAbilityPromise011 fail: `);
expect().assertFail();
done();
}).catch((error) => {
console.log(`testStartAbilityPromise011 error.code: ` + error.code);
expect(true).assertTrue();
done();
})
} catch (err) {
console.log(`testStartAbilityPromise011 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_1200
* @tc.name : testStartAbilityPromise012
* @tc.desc : test startAbility right
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise012', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": "entryTest",
"parameters": {
"key1": true,
"key2": 1,
"key3": "this is string"
}
}
context.startAbility(want).then(() => {
console.info('testStartAbilityPromise012 start successful.');
}).catch((error) => {
console.error('testStartAbilityPromise012 start failed. Cause: ' + JSON.stringify(error));
})
await sleep(1500);
const result = globalThis.list1;
const parameters = globalThis.parameters;
console.info('result: ' + JSON.stringify(result));
console.info('parameters: ' + JSON.stringify(parameters));
expect(result[0]).assertEqual('MainAbility1 onCreate');
expect(parameters.key1).assertEqual(true);
expect(parameters.key2).assertEqual(1);
expect(parameters.key3).assertEqual("this is string");
let context1: common.UIAbilityContext = globalThis.ability1Context;
context1.terminateSelf();
await sleep(1000);
console.log(`testStartAbilityPromise012 success`);
done();
} catch (err) {
console.log(`testStartAbilityPromise012 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_1300
* @tc.name : testStartAbilityPromise013
* @tc.desc : test startAbility right
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityPromise013', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want).then(() => {
console.info('testStartAbilityPromise013 start1 successful.');
}).catch((error) => {
console.error('testStartAbilityPromise013 start1 failed. Cause: ' + JSON.stringify(error));
})
await sleep(1000);
const result = globalThis.list1;
console.info('result: ' + JSON.stringify(result));
expect(result[0]).assertEqual('MainAbility1 onCreate');
let context1: common.UIAbilityContext = globalThis.ability1Context;
context.startAbility(want).then(() => {
console.info('testStartAbilityPromise013 start2 successful.');
}).catch((error) => {
console.error('testStartAbilityPromise013 start2 failed. Cause: ' + JSON.stringify(error));
})
await sleep(1000);
const result2 = globalThis.list1;
console.info('result2: ' + JSON.stringify(result2));
expect(result2[0]).assertEqual('MainAbility1 onCreate');
let context2: common.UIAbilityContext = globalThis.ability1Context;
context1.terminateSelf();
await sleep(1000);
context2.terminateSelf();
await sleep(1000);
console.log(`testStartAbilityPromise013 success`);
done();
} catch (err) {
console.log(`testStartAbilityPromise013 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0100
* @tc.name : testStartAbilityCallback001
* @tc.desc : test startAbility right
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback001 fail: ` + err);
expect().assertFail();
done();
}
console.info('testStartAbilityCallback001 startAbility succeed');
})
await sleep(1500);
const result = globalThis.list1;
console.info('result: ' + JSON.stringify(result));
expect(result[0]).assertEqual('MainAbility1 onCreate');
let context1: common.UIAbilityContext = globalThis.ability1Context;
context1.terminateSelf();
await sleep(1000);
console.log(`testStartAbilityCallback001 success`);
done();
} catch (err) {
console.log(`testStartAbilityCallback001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0200
* @tc.name : testStartAbilityCallback002
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback002', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.abc",
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback002 err.code: ` + err.code);
expect(true).assertTrue();
done();
} else {
expect().assertFail();
done();
}
})
} catch (err) {
console.log(`testStartAbilityCallback002 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0300
* @tc.name : testStartAbilityCallback003
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback003', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": " ",
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback003 err.code: ` + err.code);
expect(true).assertTrue();
done();
} else {
expect().assertFail();
done();
}
})
} catch (err) {
console.log(`testStartAbilityCallback003 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0400
* @tc.name : testStartAbilityCallback004
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback004', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback004 err.code: ` + err.code);
expect(true).assertTrue();
done();
} else {
expect().assertFail();
done();
}
})
} catch (err) {
console.log(`testStartAbilityCallback004 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0500
* @tc.name : testStartAbilityCallback005
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback005', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": "abc"
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback005 err.code: ` + err.code);
expect(true).assertTrue();
done();
} else {
expect().assertFail();
done();
}
})
} catch (err) {
console.log(`testStartAbilityCallback005 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0600
* @tc.name : testStartAbilityCallback006
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback006', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": " "
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback006 err.code: ` + err.code);
expect(true).assertTrue();
done();
} else {
expect().assertFail();
done();
}
})
} catch (err) {
console.log(`testStartAbilityCallback006 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0800
* @tc.name : testStartAbilityCallback008
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback008', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "abc",
"moduleName": "entryTest"
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback008 err.code: ` + err.code);
expect(true).assertTrue();
done();
} else {
expect().assertFail();
done();
}
})
} catch (err) {
console.log(`testStartAbilityCallback008 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0900
* @tc.name : testStartAbilityCallback009
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback009', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": " ",
"moduleName": "entryTest"
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback009 err.code: ` + err.code);
expect(true).assertTrue();
done();
} else {
expect().assertFail();
done();
}
})
} catch (err) {
console.log(`testStartAbilityCallback009 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_1000
* @tc.name : testStartAbilityCallback010
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback010', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"moduleName": "entryTest"
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback010 err.code: ` + err.code);
expect(true).assertTrue();
done();
} else {
expect().assertFail();
done();
}
})
} catch (err) {
console.log(`testStartAbilityCallback010 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_1100
* @tc.name : testStartAbilityCallback011
* @tc.desc : test startAbility wrong want
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback011', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback011 err.code: ` + err.code);
expect(true).assertTrue();
done();
} else {
expect().assertFail();
done();
}
})
} catch (err) {
console.log(`testStartAbilityCallback011 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_1200
* @tc.name : testStartAbilityCallback012
* @tc.desc : test startAbility right
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback012', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": "entryTest",
"parameters": {
"key1": true,
"key2": 1,
"key3": "this is string"
}
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback012 fail: ` + err);
expect().assertFail();
done();
return;
}
console.info('testStartAbilityCallback012 startAbility succeed');
})
await sleep(1500);
const result = globalThis.list1;
const parameters = globalThis.parameters;
console.info('result: ' + JSON.stringify(result));
console.info('parameters: ' + JSON.stringify(parameters));
expect(result[0]).assertEqual('MainAbility1 onCreate');
expect(parameters.key1).assertEqual(true);
expect(parameters.key2).assertEqual(1);
expect(parameters.key3).assertEqual("this is string");
let context1: common.UIAbilityContext = globalThis.ability1Context;
context1.terminateSelf();
await sleep(1000);
console.log(`testStartAbilityCallback012 success`);
done();
} catch (err) {
console.log(`testStartAbilityCallback012 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_1300
* @tc.name : testStartAbilityCallback013
* @tc.desc : test startAbility right
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('testStartAbilityCallback013', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback013 fail1: ` + err);
expect().assertFail();
done();
return;
}
console.info('testStartAbilityCallback013 startAbility1 succeed');
})
await sleep(1000);
const result = globalThis.list1;
console.info('result: ' + JSON.stringify(result));
expect(result[0]).assertEqual('MainAbility1 onCreate');
let context1: common.UIAbilityContext = globalThis.ability1Context;
context.startAbility(want, (err) => {
if (err.code) {
console.log(`testStartAbilityCallback013 fail2: ` + err);
expect().assertFail();
done();
return;
}
console.info('testStartAbilityCallback013 startAbility2 succeed');
})
await sleep(1000);
const result2 = globalThis.list1;
console.info('result: ' + JSON.stringify(result2));
expect(result2[0]).assertEqual('MainAbility1 onCreate');
let context2: common.UIAbilityContext = globalThis.ability1Context;
context1.terminateSelf();
await sleep(1000);
context2.terminateSelf();
await sleep(1000);
console.log(`testStartAbilityCallback013 success`);
done();
} catch (err) {
console.log(`testStartAbilityCallback013 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_APPLICATIONINFO_PROMISE_0100
* @tc.name : testApplicationInfoPromise001
* @tc.desc : test filed of applicationInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testTerminateSelfPromise001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want).then(() => {
console.info('testTerminateSelfPromise001 start successful. ');
}).catch((error) => {
console.error('testTerminateSelfPromise001 start failed. Cause: ' + JSON.stringify(error));
})
await sleep(1500);
let context1: common.UIAbilityContext = globalThis.ability1Context;
context1.terminateSelf();
await sleep(1000);
const result = globalThis.list1;
console.info('result: ' + JSON.stringify(result));
expect(result[1]).assertEqual('MainAbility1 onDestroy');
console.log(`testTerminateSelfPromise001 success`);
done();
} catch (err) {
console.log(`testTerminateSelfPromise001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_APPLICATIONINFO_CALLBACK_0100
* @tc.name : testApplicationInfoCallback001
* @tc.desc : test filed of applicationInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testApplicationInfoCallback001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
var want = {
"bundleName": "com.example.contexttest",
"abilityName": "MainAbility1",
"moduleName": "entryTest"
}
context.startAbility(want).then(() => {
console.info('testApplicationInfoCallback001 start successful. ');
}).catch((error) => {
console.error('testApplicationInfoCallback001 start failed. Cause: ' + JSON.stringify(error));
})
await sleep(1500);
let context1: common.UIAbilityContext = globalThis.ability1Context;
context1.terminateSelf((err) => {
if (err.code) {
console.log(`testApplicationInfoCallback001 fail: ` + err);
expect().assertFail();
done();
}
})
await sleep(1000);
const result = globalThis.list1;
console.info('result: ' + JSON.stringify(result));
expect(result[1]).assertEqual('MainAbility1 onDestroy');
console.log(`testApplicationInfoCallback001 success`);
done();
} catch (err) {
console.log(`testApplicationInfoCallback001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_STAGEMODE_0100
* @tc.name : testStageMode001
* @tc.desc : test filed of stageMode
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testStageMode001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context.stageMode).assertTrue();
console.log(`testStageMode001 success`);
done();
} catch (err) {
console.log(`testStageMode001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_RESOURCEMANAGER_0100
* @tc.name : testResourceManager001
* @tc.desc : test filed of resourceManager
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testResourceManager001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context.resourceManager != null).assertTrue();
console.log(`testResourceManager001 success`);
done();
} catch (err) {
console.log(`testResourceManager001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_APPLICATIONINFO_0100
* @tc.name : testApplicationInfo001
* @tc.desc : test filed of applicationInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testApplicationInfo001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
let applicationInfo = context.applicationInfo;
expect(applicationInfo != null).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.name: ` + applicationInfo.name);
expect(applicationInfo.name == 'com.example.contexttest').assertTrue();
console.log(`testApplicationInfo001 applicationInfo.description: ` + applicationInfo.description.length);
expect(applicationInfo.description.length >= 0).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.descriptionId: ` + applicationInfo.descriptionId);
expect(applicationInfo.descriptionId == 0).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.label: ` + applicationInfo.label);
expect(applicationInfo.label == '$string:app_name').assertTrue();
console.log(`testApplicationInfo001 applicationInfo.labelId: ` + applicationInfo.labelId);
expect(applicationInfo.labelId != null).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.icon: ` + applicationInfo.icon);
expect(applicationInfo.icon == '$media:app_icon').assertTrue();
console.log(`testApplicationInfo001 applicationInfo.iconId: ` + applicationInfo.iconId);
expect(applicationInfo.iconId != null).assertTrue();
console.log(`testApplicationInfo001 applicationInfo.codePath: ` + applicationInfo.codePath);
expect(typeof (applicationInfo.codePath) == 'string').assertTrue();
console.log(`testApplicationInfo001 success`);
done();
} catch (err) {
console.log(`testApplicationInfo001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CACHEDIR_0100
* @tc.name : testCacheDir001
* @tc.desc : test filed of cacheDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testCacheDir001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
console.log(`testCacheDir001 cacheDir:` + context.cacheDir);
expect(typeof (context.cacheDir) == 'string').assertTrue();
console.log(`testCacheDir001 success`);
done();
} catch (err) {
console.log(`testCacheDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_TEMPDIR_0100
* @tc.name : testTempDir001
* @tc.desc : test filed of tempDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testTempDir001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
console.log(`testTempDir001 tempDir:` + context.tempDir);
expect(typeof (context.tempDir) == 'string').assertTrue();
console.log(`testTempDir001 success`);
done();
} catch (err) {
console.log(`testTempDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_FILESDIR_0100
* @tc.name : testFilesDir001
* @tc.desc : test filed of filesDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testFilesDir001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
console.log(`testFilesDir001 filesDir:` + context.filesDir);
expect(typeof (context.filesDir) == 'string').assertTrue();
console.log(`testFilesDir001 success`);
done();
} catch (err) {
console.log(`testFilesDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_DATABASEDIR_0100
* @tc.name : testDatabaseDir001
* @tc.desc : test filed of databaseDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testDatabaseDir001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
console.log(`testDatabaseDir001 databaseDir:` + context.databaseDir);
expect(typeof (context.databaseDir) == 'string').assertTrue();
console.log(`testDatabaseDir001 success`);
done();
} catch (err) {
console.log(`testDatabaseDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_PREFERENCESDIR_0100
* @tc.name : testPreferencesDir001
* @tc.desc : test filed of preferencesDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testPreferencesDir001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
console.log(`testPreferencesDir001 preferencesDir:` + context.preferencesDir);
expect(typeof (context.preferencesDir) == 'string').assertTrue();
console.log(`testPreferencesDir001 success`);
done();
} catch (err) {
console.log(`testPreferencesDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_BUNDLECODEDIR_0100
* @tc.name : testBundleCodeDir001
* @tc.desc : test filed of bundleCodeDir
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('testBundleCodeDir001', 0, async function (done) {
try {
let context: common.UIAbilityContext = globalThis.abilityContext;
console.log(`testBundleCodeDir001 bundleCodeDir:` + context.bundleCodeDir);
expect(typeof (context.bundleCodeDir) == 'string').assertTrue();
console.log(`testBundleCodeDir001 success`);
done();
} catch (err) {
console.log(`testBundleCodeDir001 fail: ` + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0100
* @tc.name : testCreateModuleContext001
* @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap1
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext001", 0, async function (done) {
try {
console.info("testCreateModuleContext001 begin");
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
let moduleContext = context.createModuleContext("entry");
expect(moduleContext != null).assertTrue();
bundleName = moduleContext.applicationInfo.name;
console.info("testCreateModuleContext001 bundleName: " + bundleName);
expect(bundleName).assertEqual("com.example.contexttest");
done();
} catch (err) {
console.info("testCreateModuleContext001 err: " + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_002
* @tc.name : testCreateModuleContext002
* @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap2
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext002", 0, async function (done) {
try {
console.log("testCreateModuleContext002 begin");
let context: common.UIAbilityContext = globalThis.abilityContext;
expect(context != null).assertTrue();
let moduleContext = context.createModuleContext("entryTest");
expect(moduleContext != null).assertTrue();
bundleName = moduleContext.applicationInfo.name;
console.info("testCreateModuleContext002 bundleName: " + bundleName);
expect(bundleName).assertEqual("com.example.contexttest");
done();
} catch (err) {
console.info("testCreateModuleContext002 err: " + err);
expect().assertFail();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_003
* @tc.name : testCreateModuleContext003
* @tc.desc : Context calls createModuleContext, passing in the moduleName of the cross-application hap1
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext003", 0, async function (done) {
try {
console.info("testCreateModuleContext003 begin");
let context: common.UIAbilityContext = globalThis.abilityContext;
let moduleContext = context.createModuleContext("entry_assist");
expect(!moduleContext).assertTrue();
done();
} catch (err) {
let e = err.toString();
let errLog = "Invalid input parameter"
console.debug("testCreateModuleContext003 ====>e====>" + e);
expect(e.indexOf(errLog) >= 0).assertTrue();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_004
* @tc.name : testCreateModuleContext004
* @tc.desc : Context calls createModuleContext, passing in a non-existing moduleName
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext004", 0, async function (done) {
try {
console.info("testCreateModuleContext004 begin");
let context: common.UIAbilityContext = globalThis.abilityContext;
let moduleContext = context.createModuleContext("abc");
expect(!moduleContext).assertTrue();
done();
} catch (err) {
let e = err.toString();
let errLog = "Invalid input parameter"
console.debug("testCreateModuleContext004 ====>e====>" + e);
expect(e.indexOf(errLog) >= 0).assertTrue();
done();
}
})
/**
* @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_005
* @tc.name : testCreateModuleContext005
* @tc.desc : Context calls createModuleContext, and the incoming moduleName is undefined
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testCreateModuleContext005", 0, async function (done) {
try {
console.info("testCreateModuleContext005 begin");
let context: common.UIAbilityContext = globalThis.abilityContext;
let moduleContext = context.createModuleContext(undefined);
expect(moduleContext != null).assertTrue();
done();
} catch (err) {
let e = err.toString();
let errLog = "Invalid input parameter"
console.debug("testCreateModuleContext005 ====>e====>" + e);
expect(e.indexOf(errLog) >= 0).assertTrue();
done();
}
})
/**
* @tc.number : ABILITY_TEST_GETAPPLICATIONCONTEXT_0100
* @tc.name : testGetApplicationContext001
* @tc.desc : test getApplicationContext return not empty
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("testGetApplicationContext001", 0, async function (done) {
try {
console.info("testGetApplicationContext001 begin");
let context: common.UIAbilityContext = globalThis.abilityContext;
let applicationContext = context.getApplicationContext();
expect(applicationContext != null).assertTrue();
console.info("testGetApplicationContext001 success");
done();
} catch (err) {
console.log(`testGetApplicationContext001 fail: ` + err);
expect().assertFail();
done();
}
});
})
}
{
"module": {
"name": "entryTest",
"type": "feature",
"description": "$string:module_test_desc",
"srcEntry": "./ets/Application/AbilityStage.ts",
"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"
]
}
]
},
{
"name": "MainAbility1",
"srcEntry": "./ets/MainAbility1/MainAbility1.ts",
"description": "$string:MainAbility1_desc",
"icon": "$media:icon",
"label": "$string:MainAbility1_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"launchType": "multiton"
}
]
}
}
\ No newline at end of file
{
"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"
},
{
"name": "MainAbility1_desc",
"value": "description"
},
{
"name": "MainAbility1_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.contexttest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"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_hap_assist_suite("context_entry_ets_normal_test") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsAbilityContextEntryTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
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"
}
\ No newline at end of file
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}
\ 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 Ability from '@ohos.app.ability.UIAbility'
const abilityname = 'FeatureMainAbility';
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant1 = want;
console.log("[Demo] MainAbility context: " + JSON.stringify(this.context));
var listKey1 = [];
let AbilityLifecycleCallback = {
onAbilityCreate(ability) {
console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate ability:"
+ JSON.stringify(ability));
console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate abilityname:"
+ JSON.stringify(abilityname));
console.log("[Demo] " + abilityname + " onAbilityCreate");
listKey1.push(abilityname + " onAbilityCreate");
console.log("[Demo] 1listKey1:" + JSON.stringify(listKey1));
},
onWindowStageCreate(ability, windowStage) {
console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate ability:"
+ JSON.stringify(ability));
console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate abilityname:"
+ JSON.stringify(abilityname));
console.log("[Demo] " + abilityname + " onWindowStageCreate");
listKey1.push(abilityname + " onWindowStageCreate");
console.log("[Demo] 2listKey1:" + JSON.stringify(listKey1));
},
onWindowStageActive(ability, windowStage) {
console.log(abilityname + " onWindowStageActive")
},
onWindowStageInactive(ability, windowStage) {
console.log(abilityname + " onWindowStageInactive")
},
onWindowStageDestroy(ability, windowStage) {
console.log("[Demo] AbilityLifecycleCallback1 onWindowStageDestroy ability:"
+ JSON.stringify(ability));
listKey1.push(abilityname + " onWindowStageDestroy");
console.log("[Demo] 3listKey1:" + JSON.stringify(listKey1));
},
onAbilityDestroy(ability) {
console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy ability:"
+ JSON.stringify(ability));
console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy abilityname:"
+ JSON.stringify(abilityname));
console.log("[Demo] " + abilityname + " onAbilityDestroy");
listKey1.push(abilityname + " onAbilityDestroy");
console.log("[Demo] 4listKey1:" + JSON.stringify(listKey1));
},
onAbilityForeground(ability) {
console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground ability:"
+ JSON.stringify(ability));
console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground abilityname:"
+ JSON.stringify(abilityname));
console.log("[Demo] " + abilityname + " onAbilityForeground");
listKey1.push(abilityname + " onAbilityForeground");
console.log("[Demo] 5listKey1:" + JSON.stringify(listKey1));
},
onAbilityBackground(ability) {
console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground ability:"
+ JSON.stringify(ability));
console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground abilityname:"
+ JSON.stringify(abilityname));
console.log("[Demo] " + abilityname + " onAbilityBackground");
listKey1.push(abilityname + " onAbilityBackground");
console.log("[Demo] 6listKey1:" + JSON.stringify(listKey1));
},
onAbilityContinue(ability) {
console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue ability:"
+ JSON.stringify(ability));
console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue abilityname:"
+ JSON.stringify(abilityname));
console.log("[Demo] " + abilityname + " onAbilityContinue");
listKey1.push(abilityname + " onAbilityContinue");
console.log("[Demo] 7listKey1:" + JSON.stringify(listKey1));
}
}
globalThis.applicationContext1 = this.context.getApplicationContext();
// let lifecycleid = globalThis.applicationContext1.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
let lifecycleid = globalThis.applicationContext1.on('abilityLifecycle', AbilityLifecycleCallback);
console.log("[Demo] registerAbilityLifecycleCallback1 number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] registerAbilityLifecycleCallback1 listKey: " + JSON.stringify(listKey1));
globalThis.featureList1 = listKey1;
globalThis.featureCallbackid1 = lifecycleid;
}, 1500);
}
onDestroy() {
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.featureAbilityContext = this.context;
// windowStage.setUIContent(this.context, "testability/pages/index1", null)
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
console.log('MainAbility loadContent error');
return;
}
console.log('MainAbility loadContent success');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};
/*
* 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.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "entry",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "MainAbility",
"srcEntry": "./ets/mainability/MainAbility.ts",
"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.
先完成此消息的编辑!
想要评论请 注册