提交 290a61c1 编写于 作者: C chengxingzhen

xts-AppContext新增用例

Signed-off-by: Nchengxingzhen <chengxingzhen@huawei.com>
上级 b2ebd159
......@@ -21,6 +21,7 @@ group("context") {
"actscreatemodulecontextassist:ActsCreateModuleContextAssist",
"actscreatemodulecontextassistone:ActsCreateModuleContextAssistOne",
"actscreatemodulecontexttest:ActsCreateModuleContextTest",
"actsstageappcontext:actsstageappcontext",
"actsstagecontext:actsstagecontext",
"scene/defpermission:DefPermission",
]
......
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
group("actsstageappcontext") {
testonly = true
if (is_standard_system) {
deps = [
#"actsstagecontextassistone:ActsStageContextAssistOne",
#"actsstagecontextassisttwo:ActsStageContextAssistTwo",
"actsstageappcontexttest:ActsStageAppContextTest",
]
}
}
{
"app": {
"bundleName": "com.example.stageappcontexttest",
"vendor": "huawei",
"versionCode": 1000000,
"versionName": "1.0.0",
"debug": false,
"icon" : "$media:icon",
"label" : "$string:app_name",
"description" : "$string:description_application",
"distributedNotificationEnabled": true,
"keepAlive" : true,
"singleUser": true,
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": false
}
}
}
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsStageAppContextTest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":stageappcontext_js_assets",
":stageappcontext_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsStageAppContextTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("stageappcontext_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("stageappcontext_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("stageappcontext_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":stageappcontext_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for aceceshi Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"bundle-name": "com.example.stageappcontexttest",
"module-name": "entry_test",
"shell-timeout": "600000",
"testcase-timeout": "15000"
},
"kits": [
{
"test-file-name": [
"ActsStageAppContextTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.info("MyAbilityStageAppContext onCreate")
globalThis.abilityStageContext = this.context
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.application.Ability'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability
console.log("ActsStageAppContextTest MainAbility onCreate")
globalThis.abilityWant = want;
globalThis.abilityContext = this.context
let abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("ActsStageAppContextTest MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("ActsStageAppContextTest MainAbility onWindowStageCreate")
windowStage.setUIContent(this.context, "pages/index/index", null)
console.log("ActsStageAppContextTest MainAbility onWindowStageCreate finish")
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("ActsStageAppContextTest MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("ActsStageAppContextTest MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("ActsStageAppContextTest MainAbility onBackground")
}
};
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import rpc from '@ohos.rpc';
import ServiceExtension from '@ohos.application.ServiceExtensionAbility'
export default class ServiceAbility extends ServiceExtension {
onCreate(want) {
console.log('ActsStageAppContextTest ServiceAbility onCreate, want: ' + want.abilityName);
globalThis.serviceExtenxionAbilityContext = this.context
}
onRequest(want, startId) {
console.log('ServiceAbility onRequest, want: ' + want.abilityName + ', startId: ' + startId);
}
onConnect(want) {
console.log('ActsStageAppContextTest ServiceAbility onConnect, want:' + want.abilityName);
if (want.action == 'StartAbilityPromise') {
console.log('stub SerivceAbilityServer OnConnect start 1');
console.log('=======startAbilityPromise=======');
return new rpc.RemoteObject('ServiceAbility');
}
}
onDisconnect(want) {
console.log('ActsStageAppContextTest ServiceAbility onDisconnect, want:' + want.abilityName);
}
onDestroy() {
console.log('ActsStageAppContextTest ServiceAbility onDestroy');
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
let abilityDelegator = undefined
let abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.log("onAbilityCreateCallback");
}
async function addAbilityMonitorCallback(err: any) {
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
console.info("OpenHarmonyTestRunner OnPrepare ")
}
async onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
globalThis.abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
let cmd = 'aa start -d 0 -a MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
console.info('OpenHarmonyTestRunner onRun end')
}
};
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Entry
@Component
struct Index {
aboutToAppear(){
}
build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('MainAbility Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "SecondMainAbility Page"
build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import stageAppContextTest from './StageAppContext.test'
export default function testsuite() {
stageAppContextTest(globalThis.abilityContext)
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it, expect, beforeAll } from '@ohos/hypium'
let TAG;
export default function stageAppContextTest(abilityContext) {
describe('ActsStageAppContextTest', function () {
beforeAll(async (done) => {
console.log("ActsStageContextPropertiesTest afterAll called");
await abilityContext.startAbility({
bundleName: "com.example.stageappcontexttest",
abilityName: "ServiceAbility",
}).then((data) => {
console.log('ActsStageContextPropertiesTest - ServiceAbility: ' + JSON.stringify(data));
}).catch((err) => {
console.log("ActsStageContextPropertiesTest - ServiceAbility failed: "
+ JSON.stringify(err));
done()
})
setTimeout(function () {
console.log("ActsStageContextPropertiesTest afterAll end");
done();
}, 1000);
})
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_0100
* @tc.name: Validating the context obtained by the AbilityContext call
* getApplicationContext can be obtained using createBundleContext
* @tc.desc: Function test
* @tc.level 0
*/
it('SUB_AA_OpenHarmony_ApplicationContext_0100', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_0100";
console.log(TAG + " --- start");
let context = abilityContext.getApplicationContext();
let result = context.createBundleContext('com.example.stageappcontexttest')
let getCacheDir = result.cacheDir
console.log(TAG + 'getCacheDir::' + JSON.stringify(getCacheDir));
expect(getCacheDir).assertEqual('/data/app/el2/100/base/com.example.stageappcontexttest/cache')
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_0200
* @tc.name: Validating the context obtained by the AbilityContext call
* getApplicationContext can be obtained using getApplicationContext
* @tc.desc: Function test
* @tc.level 0
*/
it('SUB_AA_OpenHarmony_ApplicationContext_0200', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_0200";
console.log(TAG + " --- start");
let context = abilityContext.getApplicationContext();
let result = context.getApplicationContext()
let getCacheDir = result.cacheDir
console.log(TAG + 'getCacheDir::' + JSON.stringify(getCacheDir));
expect(getCacheDir).assertEqual('/data/storage/el2/base/cache')
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_0300
* @tc.name: Verify that the AbilityContext call getApplicationContext
* gets the context using resourceManger
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_0300', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_0300";
console.log(TAG + " --- start");
let context = abilityContext.getApplicationContext();
let result = await context.resourceManager.getString(16777219);
console.log(TAG + " result = " + JSON.stringify(result));
expect(result).assertEqual("entry_MainAbility");
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_0400
* @tc.name: Verify that the AbilityContext call getApplicationContext
* gets the context using applicationInfo
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_0400', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_0400";
console.log(TAG + " --- start");
let context = abilityContext.getApplicationContext();
let result = context.applicationInfo.name;
console.log(TAG + " result = " + JSON.stringify(result));
expect(result).assertEqual("com.example.stageappcontexttest");
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_0500
* @tc.name: Validating the context obtained by the AbilityStageContext call
* getApplicationContext can be obtained using getApplicationContext
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_0500', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_0500";
console.log(TAG + " --- start");
let context = globalThis.abilityStageContext.getApplicationContext();
let result = context.getApplicationContext()
let getCacheDir = result.cacheDir
console.log(TAG + 'getCacheDir::' + JSON.stringify(getCacheDir));
expect(getCacheDir).assertEqual('/data/storage/el2/base/cache')
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_0600
* @tc.name: Verify that the AbilityStageContext call getApplicationContext
* gets the context using applicationInfo
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_0600', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_0600";
console.log(TAG + " --- start");
let context = globalThis.abilityStageContext.getApplicationContext();
let result = context.applicationInfo.name;
console.log(TAG + " result = " + JSON.stringify(result));
expect(result).assertEqual("com.example.stageappcontexttest");
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_0700
* @tc.name: Validating the context obtained by the ExtensionContext call
* getApplicationContext can be obtained using createBundleContext
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_0700', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_0700";
console.log(TAG + " --- start");
let context = globalThis.serviceExtenxionAbilityContext.getApplicationContext();
let result = context.createBundleContext('com.example.stageappcontexttest')
let getCacheDir = result.cacheDir
console.log(TAG + 'getCacheDir::' + JSON.stringify(getCacheDir));
expect(getCacheDir).assertEqual('/data/app/el2/100/base/com.example.stageappcontexttest/cache')
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_0800
* @tc.name: Validating the context obtained by the ExtensionContext call
* getApplicationContext can be obtained using getApplicationContext
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_0800', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_0800";
console.log(TAG + " --- start");
let serviceContext = globalThis.serviceExtenxionAbilityContext.getApplicationContext()
console.log(TAG + "servicecontext" + serviceContext)
let result = serviceContext.getApplicationContext();
console.log(TAG + " result = " + result);
let dir = serviceContext.cacheDir
console.log(TAG + " dir = " + dir);
expect(dir).assertEqual("/data/storage/el2/base/cache");
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_0900
* @tc.name: Verify that the ExtensionContext call getApplicationContext
* gets the context using resourceManger
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_0900', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_0900";
console.log(TAG + " --- start");
let serviceContext = globalThis.serviceExtenxionAbilityContext.getApplicationContext();
let result = await serviceContext.resourceManager.getString(16777219);
console.log(TAG + " result = " + result);
expect(result).assertEqual("entry_MainAbility");
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_1000
* @tc.name: Verify that the ExtensionContext call getApplicationContext
* gets the context using applicationInfo
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_1000', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_1000";
console.log(TAG + " --- start");
let serviceContext = globalThis.serviceExtenxionAbilityContext.getApplicationContext();
let result = serviceContext.applicationInfo.name;
console.log(TAG + " result = " + result);
expect(result).assertEqual("com.example.stageappcontexttest");
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_1100
* @tc.name: Verify that the application-level context call interface
* getApplicationContext gets the context using createBundleContext
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_1100', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_1100";
console.log(TAG + " --- start");
let context = abilityContext.getApplicationContext();
let context2 = context.getApplicationContext();
let result = context2.createBundleContext("com.example.stageappcontexttest");
let dir = result.cacheDir;
console.log(TAG + " dir = " + dir);
expect(dir).assertEqual("/data/app/el2/100/base/com.example.stageappcontexttest/cache");
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_1200
* @tc.name: Verify that the app-level context calls the interface
* getApplicationContext to get the context using getApplicationContext
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_1200', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_1200";
console.log(TAG + " --- start");
let context = abilityContext.getApplicationContext();
let context2 = context.getApplicationContext();
let result = context2.getApplicationContext();
let dir = result.cacheDir;
console.log(TAG + " dir = " + dir);
expect(dir).assertEqual("/data/storage/el2/base/cache");
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_1300
* @tc.name: Verify that the context obtained by the application-level
* context calling interface getApplicationContext can use resourceManger
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_1300', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_1300";
console.log(TAG + " --- start");
let context = abilityContext.getApplicationContext();
let context2 = context.getApplicationContext();
let result = await context2.resourceManager.getString(16777219);
console.log(TAG + " result = " + result);
expect(result).assertEqual("entry_MainAbility");
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_1400
* @tc.name: Verify that the application-level context calling interface
* getApplicationContext gets the context using applicationInfo
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_1400', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_1400";
console.log(TAG + " --- start");
let context = abilityContext.getApplicationContext();
let context2 = context.getApplicationContext();
let result = context2.applicationInfo.name;
console.log(TAG + " result = " + result);
expect(result).assertEqual("com.example.stageappcontexttest");
done();
});
/**
* @tc.number: SUB_AA_OpenHarmony_ApplicationContext_1500
* @tc.name: Verify that the context obtained by the app-level context
* calling interface getApplicationContext can be obtained using getApplicationContext
* @tc.desc: Function test
* @tc.level 3
*/
it('SUB_AA_OpenHarmony_ApplicationContext_1500', 0, async function (done) {
let TAG = "SUB_AA_OpenHarmony_ApplicationContext_1500";
console.log(TAG + " --- start");
let context = abilityContext.getApplicationContext();
let context2 = context.getApplicationContext();
let result = context2.getApplicationContext();
console.log(TAG + " result = " + JSON.stringify(result));
expect(result.tempDir).assertEqual("/data/storage/el2/base/temp");
expect(result.filesDir).assertEqual("/data/storage/el2/base/files");
expect(result.distributedFilesDir).assertEqual("/data/storage/el2/distributedfiles");
expect(result.databaseDir).assertEqual("/data/storage/el2/database");
expect(result.preferencesDir).assertEqual("/data/storage/el2/base/preferences");
expect(result.bundleCodeDir).assertEqual("/data/storage/el1/bundle");
done();
});
})
}
\ No newline at end of file
{
"module": {
"name": "entry_test",
"type": "entry",
"srcEntrance": "./ets/Application/MyAbilityStage.ts",
"description": "$string:entry_test_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"uiSyntax": "ets",
"abilities": [
{
"name": "MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:MainAbility_desc",
"icon": "$media:icon",
"label": "$string:MainAbility_label",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
],
"extensionAbilities": [
{
"name": "ServiceAbility",
"srcEntrance": "./ets/ServiceAbility/ServiceAbility.ts",
"label": "$string:form_ServiceAbility_label",
"description": "$string:form_ServiceAbility_desc",
"type": "service"
}
],
"requestPermissions": [
{
"name":"ohos.permission.START_ABILITIES_FROM_BACKGROUND",
"reason":"need use ohos.permission.START_ABILITIES_FROM_BACKGROUND"
}
]
}
}
\ No newline at end of file
{
"string": [
{
"name": "entry_test_desc",
"value": "description"
},
{
"name": "app_name",
"value": "ActsStageContextPropertiesTest"
},
{
"name": "description_application",
"value": "demo for test"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "entry_MainAbility"
},
{
"name": "form_ServiceAbility_desc",
"value": "form_description"
},
{
"name": "form_ServiceAbility_label",
"value": "form_label"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册