mirror of
https://gitee.com/openharmony/applications_app_samples
synced 2024-11-23 08:30:06 +00:00
testcase for memoryShared in PerformanceLibrary
Signed-off-by: ZhaoBohan <zhaobohan2@huawei.com>
This commit is contained in:
parent
42ecd12fbb
commit
2e5cb22b11
@ -82,6 +82,14 @@ BackgroundTask使用说明:
|
||||
|
||||
3.点击**长时任务**按钮进入场景页,授予通知权限和定位权限,和点击**开启定位服务**按钮开启定位,点击**关闭定位服务**关闭定位。
|
||||
|
||||
多线程共享内存页面使用说明:
|
||||
|
||||
1.点击性能示例主页的**MemoryShared**按钮,进入**多线程共享内存入口**场景页。
|
||||
|
||||
2.点击多线程共享内存入口页的**原子操作对比**按钮,进入**原子操作主页**。
|
||||
|
||||
3.点击多线程共享内存入口页的**锁的使用**按钮,进入**锁的使用子页面**。
|
||||
|
||||
### 工程目录
|
||||
|
||||
```
|
||||
@ -201,7 +209,11 @@ products/phone/entry/src/main/ets
|
||||
| | |---TransientTask.ets // 短时任务页面
|
||||
| | |---LongTermTask.ets // 长时任务页面
|
||||
| |---/trace
|
||||
| | |---TracePage.ets // 懒加载示例首页
|
||||
| | |---TracePage.ets // 懒加载示例首页
|
||||
| |---/memoryShared
|
||||
| | |---AtomicsUsage.ets // 原子操作页面
|
||||
| | |---LockUsage.ets // 锁应用页面
|
||||
| | |---MemorySharedHome.ets // 多线程共享内存入口页面
|
||||
| |---/Index
|
||||
|---/utils
|
||||
| |---Logger.ets // 封装整个日志
|
||||
@ -278,6 +290,14 @@ products/phone/entry/src/main/ets
|
||||
* 模拟后台导航定位场景,申请定位类型长时任务,使用@ohos.geoLocationManager实现位置定位功能,必须在联网环境才能获取定位数据
|
||||
* 源码链接:[LongTermTaskView.ets](feature/backgroundTask/src/main/ets/view/LongTermTaskView.ets)
|
||||
|
||||
* 多线程共享内存页面模块
|
||||
* 原子操作场景
|
||||
* 使用原子或非原子操作,实现多线程操作累加器
|
||||
* 源码链接:[AtomicsUsage.ets](feature/memoryShared/src/main/ets/pages/AtomicsUsage.ets)
|
||||
* 锁应用场景
|
||||
* 使用或不适用锁,实现多线程写入文件
|
||||
* 源码链接:[LockUsage.ets](feature/memoryShared/src/main/ets/pages/LockUsage.ets)
|
||||
|
||||
### 相关权限
|
||||
|
||||
ohos.permission.INTERNET
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
export default class Constants {
|
||||
// 用于列表中图片总数
|
||||
public static readonly IMAGE_TOTAL_NUM: number = 1000;
|
||||
public static readonly IMAGE_TOTAL_NUM: number = 100;
|
||||
// 用于Flex中Text总数
|
||||
public static readonly TEXT_TOTAL_NUM: number = 200;
|
||||
// 用于text数字循环取模
|
||||
|
@ -16,6 +16,6 @@
|
||||
import { harTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins: [] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
||||
|
17
code/Performance/PerformanceLibrary/ohosTest.md
Normal file
17
code/Performance/PerformanceLibrary/ohosTest.md
Normal file
@ -0,0 +1,17 @@
|
||||
# PerformanceLibrary测试用例归档
|
||||
|
||||
## 用例表
|
||||
|
||||
|测试功能|预置条件|输入|预期输出|是否自动|测试结果|
|
||||
|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|
|
||||
|拉起应用| 设备正常运行| |成功拉起PerformanceLibrary应用|是|Pass|
|
||||
|进入”MemoryShared“页面| 应用正常拉起 | 点击”MemoryShared“按钮 |页面正常显示,两个按钮”原子操作对比“、”锁的使用“|是|Pass|
|
||||
|进入”原子操作对比“页面| 位于”MemoryShared“页面 | 点击”原子操作对比”按钮 |1. 正常跳转到“原子操作对比”页面<br />2. 页面正常显示,两个按钮“原子操作”、“非原子操作”|是|Pass|
|
||||
|进行原子操作任务| 位于“原子操作对比”页面 | 点击“原子操作”按钮 |打印原子操作累加结果|是|Pass|
|
||||
|进行非原子操作任务| 位于“原子操作对比”页面 | 点击“非原子操作”按钮 |打印非原子操作累加结果|是|Pass|
|
||||
|返回前一个页面| 位于“原子操作对比”页面 | 点击返回按钮 |返回到”MemoryShared“页面|是|Pass|
|
||||
|进入”锁的使用“页面| 位于”MemoryShared“页面 | 点击”锁的使用“按钮 |1. 正常跳转到“锁的使用”页面<br />2. 页面正常显示,两个按钮“使用锁”、“不使用锁”|是|Pass|
|
||||
|进行使用锁写入任务| 位于“锁的使用”页面 | 点击”使用锁“按钮 |打印“写入文件成功”|是|Pass|
|
||||
|进行不使用锁写入任务| 位于“锁的使用”页面 | 点击”不使用锁“按钮 |打印“写入文件成功”|是|Pass|
|
||||
|返回前一个页面| 位于“锁的使用”页面 | 点击返回按钮 |返回到”MemoryShared“页面|是|Pass|
|
||||
|返回前一个页面| 位于”MemoryShared“页面 | 点击返回按钮 |返回到PerformanceLibrary应用主页面|是|Pass|
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AtomicsUsage } from '@ohos/memoryShared';
|
||||
import { AtomicsUsage } from '@ohos/memoryShared/src/main/ets/pages/AtomicsUsage';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { LockUsage } from '@ohos/memoryShared';
|
||||
import { LockUsage } from '@ohos/memoryShared/src/main/ets/pages/LockUsage';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { MemorySharedHome } from '@ohos/memoryShared';
|
||||
import { MemorySharedHome } from '@ohos/memoryShared/src/main/ets/pages/MemorySharedHome';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -23,6 +23,12 @@ const BUNDLE: string = 'Performance';
|
||||
const TAG: string = '[Sample_Performance_Test]';
|
||||
const delegator: AbilityDelegatorRegistry.AbilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
|
||||
|
||||
async function getResourceString<T extends Resource>(resource: T): Promise<string> {
|
||||
let manage = delegator.getAppContext().resourceManager
|
||||
let text = await manage.getStringValue(resource)
|
||||
return text
|
||||
}
|
||||
|
||||
export default function abilityTest() {
|
||||
describe('ActsAbilityTest', () => {
|
||||
/**
|
||||
@ -597,8 +603,8 @@ export default function abilityTest() {
|
||||
await btnAccept.click();
|
||||
await driver.delayMs(3000);
|
||||
// 获取定位权限
|
||||
await driver.assertComponentExist(ON.text('允许'));
|
||||
let locAcceptBtn = await driver.findComponent(ON.text('允许'));
|
||||
await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.permission_while_use'))));
|
||||
let locAcceptBtn = await driver.findComponent(ON.text(await getResourceString($r('app.string.permission_while_use'))));
|
||||
await locAcceptBtn.click();
|
||||
await driver.delayMs(1000);
|
||||
// 点击开启定位服务
|
||||
@ -618,5 +624,63 @@ export default function abilityTest() {
|
||||
Logger.info(TAG, `${BUNDLE}BackgroundTask_001 end`);
|
||||
done();
|
||||
})
|
||||
|
||||
/**
|
||||
* 多线程共享内存页面场景
|
||||
*/
|
||||
it(BUNDLE + "memoryShared_001", 1, async (done: Function) => {
|
||||
Logger.info(TAG, `${BUNDLE}memoryShared_001 begin`);
|
||||
let driver: Driver = Driver.create();
|
||||
await driver.delayMs(1000);
|
||||
await driver.swipe(0, 800, 0, 100, 600);
|
||||
await driver.delayMs(1000);
|
||||
// 点击进入多线程共享内存页面
|
||||
let backgroundTaskBtn: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.MemoryShared'))));
|
||||
await driver.delayMs(1000);
|
||||
await backgroundTaskBtn.click();
|
||||
await driver.delayMs(1000);
|
||||
// 点击进入原子操作场景
|
||||
let AtomicSceneBtn: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.atomic_operation'))));
|
||||
await driver.delayMs(1000);
|
||||
await AtomicSceneBtn.click();
|
||||
await driver.delayMs(1000);
|
||||
// 点击进入原子操作场景
|
||||
let AtomicTaskBtn: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.use_atomic'))));
|
||||
await driver.delayMs(1000);
|
||||
await AtomicTaskBtn.click();
|
||||
await driver.delayMs(1000);
|
||||
// 点击进入原子操作场景
|
||||
let NonAtomicTaskBtn: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.not_use_atomic'))));
|
||||
await driver.delayMs(1000);
|
||||
await NonAtomicTaskBtn.click();
|
||||
await driver.delayMs(1000);
|
||||
await driver.pressBack();
|
||||
await driver.delayMs(1000);
|
||||
|
||||
// 点击进入锁的使用任务场景
|
||||
let LockSceneBtn: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.lock_operation'))));
|
||||
await driver.delayMs(1000);
|
||||
await LockSceneBtn.click();
|
||||
await driver.delayMs(1000);
|
||||
// 点击进入锁的使用任务场景
|
||||
let LockTaskBtn: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.use_lock'))));
|
||||
await driver.delayMs(1000);
|
||||
await LockTaskBtn.click();
|
||||
await driver.delayMs(2000);
|
||||
await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.write_success'))));
|
||||
// 点击进入锁的使用任务场景
|
||||
let NonLockTaskBtn: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.not_use_lock'))));
|
||||
await driver.delayMs(1000);
|
||||
await NonLockTaskBtn.click();
|
||||
await driver.delayMs(2000);
|
||||
await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.write_success'))));
|
||||
|
||||
// 退出到首页面
|
||||
await driver.pressBack();
|
||||
await driver.delayMs(1000);
|
||||
await driver.pressBack();
|
||||
Logger.info(TAG, `${BUNDLE}memoryShared_001 end`);
|
||||
done();
|
||||
})
|
||||
})
|
||||
}
|
@ -11,6 +11,38 @@
|
||||
{
|
||||
"name": "TestAbility_label",
|
||||
"value": "test label"
|
||||
},
|
||||
{
|
||||
"name": "MemoryShared",
|
||||
"value": "MemoryShared"
|
||||
},
|
||||
{
|
||||
"name": "atomic_operation",
|
||||
"value": "原子操作对比"
|
||||
},
|
||||
{
|
||||
"name": "use_atomic",
|
||||
"value": "原子操作"
|
||||
},
|
||||
{
|
||||
"name": "not_use_atomic",
|
||||
"value": "非原子操作"
|
||||
},
|
||||
{
|
||||
"name": "lock_operation",
|
||||
"value": "锁的使用"
|
||||
},
|
||||
{
|
||||
"name": "use_lock",
|
||||
"value": "使用锁"
|
||||
},
|
||||
{
|
||||
"name": "not_use_lock",
|
||||
"value": "不使用锁"
|
||||
},
|
||||
{
|
||||
"name": "write_success",
|
||||
"value": "写入文件成功"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user