Signed-off-by: qian-dan <756328797@qq.com>
This commit is contained in:
qian-dan 2024-06-21 18:38:16 +08:00
commit aa85f1683d
32 changed files with 304 additions and 148 deletions

View File

@ -264,9 +264,11 @@ Note:If the text contains special characters, please escape them according to th
<filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/screenshots/device/main.jpeg" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/> <filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/screenshots/device/main.jpeg" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/>
<filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/screenshots/device/showhighQoScomputingTime.jpeg" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/> <filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/screenshots/device/showhighQoScomputingTime.jpeg" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/>
<filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/entry/src/main/resources/base/media/icon.png" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/> <filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/entry/src/main/resources/base/media/icon.png" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/>
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/resources/base/media/icon.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/>
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/media/startIcon.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/> <filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/media/startIcon.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/>
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/media/background.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/> <filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/media/background.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/>
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/media/foreground.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/> <filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/media/foreground.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/>
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/media/icon.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/>
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/AppScope/resources/base/media/app_icon.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/> <filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/AppScope/resources/base/media/app_icon.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/>
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/screenshots/MindSporeLiteArkTSDemo.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/> <filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/screenshots/MindSporeLiteArkTSDemo.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/>
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/resources/base/media/icon.png" desc="Provided by code/DocsSample/ApplicationModels/ImplicitStartByTypeRely"/> <filteritem type="filepath" name="code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/resources/base/media/icon.png" desc="Provided by code/DocsSample/ApplicationModels/ImplicitStartByTypeRely"/>

View File

@ -9,8 +9,7 @@
使用[@ohos.effectKit](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkgraphics2d/js-apis-effectKit.md) 使用[@ohos.effectKit](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkgraphics2d/js-apis-effectKit.md)
生成effectKit,使用effectKit.getHighestSaturationColor() 生成effectKit,使用effectKit.getHighestSaturationColor()
接口实现对图片的高亮调节。添加文字/贴纸利用组件的组合编辑素材大小和位置再使用OffscreenCanvasRenderingContext2D进行离屏绘制保存。 接口实现对图片的高亮调节。添加文字/贴纸利用组件的组合编辑素材大小和位置再使用OffscreenCanvasRenderingContext2D进行离屏绘制保存。
新增图片编解码示例代码,使用[libentry.so]实现uri创建ImageSourcefd创建ImageSourcedata创建ImageSourcerawFile创建ImageSource 接口实现对图片编解码功能。可以通过uri\fd\data\rawFile将图片资源解码为ImageSource或pixelMap。可通过ImageSource/pixelMap编码为file/data。
imageSource转换为pixelMapPixelMap转为fileImageSource转为filePixelMap转为dataImageSource转为数据。
### 效果预览 ### 效果预览
@ -35,7 +34,7 @@ imageSource转换为pixelMapPixelMap转为fileImageSource转为filePixe
4. 调整菜单有裁剪、缩放、旋转、调色、修改hdr设置功能(因为有些机型设备不支持所以HDR解码后显示效果看不出来) 4. 调整菜单有裁剪、缩放、旋转、调色、修改hdr设置功能(因为有些机型设备不支持所以HDR解码后显示效果看不出来)
5. 标记菜单有添加文字、添加贴纸功能; 5. 标记菜单有添加文字、添加贴纸功能;
6. 编辑完成后,点击撤回按钮图片会还原到上一个编辑状态; 6. 编辑完成后,点击撤回按钮图片会还原到上一个编辑状态;
7. 图片编辑完成后,点击保存,会调新增的图片编解码示例代码,用页面会跳转到发表评价页面,显示相关照片; 7. 图片编辑完成后,点击保存,页面会跳转到发表评价页面,显示相关照片;
8. 点击返回按钮,退出应用。 8. 点击返回按钮,退出应用。
### 工程目录 ### 工程目录
@ -70,7 +69,7 @@ photomodify/src/main/ets/components
| |---Logger.ets // 日志工具 | |---Logger.ets // 日志工具
| |---MediaUtil.ts // 媒体帮助类 | |---MediaUtil.ts // 媒体帮助类
| |---SvgUtil.ts // svg操作帮助类 | |---SvgUtil.ts // svg操作帮助类
| |---FileUtil.ets // 数据操作帮助类 | |---FileUtil.ets // 图片编解码操作帮助类
``` ```
### 具体实现 ### 具体实现
@ -82,6 +81,12 @@ photomodify/src/main/ets/components
申请,源码参考[MainAbility.ts](entry/src/main/ets/MainAbility/MainAbility.ts) 申请,源码参考[MainAbility.ts](entry/src/main/ets/MainAbility/MainAbility.ts)
首先根据选择图片获取到的uri打开图片文件fileAsset.open选择rw'读写模式然后使用image.createImageSource创建图片源实例接下来使用createPixelMap创建PixelMap对象便于处理图片最后使用crop对图像进行裁剪处理使用scale对图像进行缩放处理rotate进行旋转处理。亮度调节使用effectKit.getHighestSaturationColor() 首先根据选择图片获取到的uri打开图片文件fileAsset.open选择rw'读写模式然后使用image.createImageSource创建图片源实例接下来使用createPixelMap创建PixelMap对象便于处理图片最后使用crop对图像进行裁剪处理使用scale对图像进行缩放处理rotate进行旋转处理。亮度调节使用effectKit.getHighestSaturationColor()
接口实现对图片的高亮调节。图片解码通过createPixelMap(DecodingOptions)并根据DecodingOptions构造参数里面的设定值(0: auto;1: SDR;2 HDR)对应创建不同的PixelMap对象。其中设置值为AUTO时会根据图片本身结构来判断是否解码为HDR内容。添加文字/贴纸编辑模式下使用组件组合Image、Shape、Text进行交互完成素材大小和位置选择编辑确认后再使用OffscreenCanvasRenderingContext2D进行离屏绘制保存为新的pixelMap。 接口实现对图片的高亮调节。图片解码通过createPixelMap(DecodingOptions)并根据DecodingOptions构造参数里面的设定值(0: auto;1: SDR;2 HDR)对应创建不同的PixelMap对象。其中设置值为AUTO时会根据图片本身结构来判断是否解码为HDR内容。添加文字/贴纸编辑模式下使用组件组合Image、Shape、Text进行交互完成素材大小和位置选择编辑确认后再使用OffscreenCanvasRenderingContext2D进行离屏绘制保存为新的pixelMap。
+ 图片编解码功能在Image中实现源码参考[Image.cpp](photomodify/src/main/cpp/Image.cpp):
+ 图片解码调用OH_ImageSourceNative_CreateFromUriOH_ImageSourceNative_CreateFromFd
OH_ImageSourceNative_CreateFromDataOH_ImageSourceNative_CreateFromRawFile等接口根据接收不同的参数调用不同的接口来创建ImageSource对象。
再通过OH_ImageSourceNative_CreatePixelmap接口将ImageSource转换为新的pixelMap。
+ 图片编码通过调用OH_ImagePackerNative_PackToFileFromPixelmapOH_ImagePackerNative_PackToFileFromImageSource
OH_ImagePackerNative_PackToDataFromPixelmapOH_ImagePackerNative_PackToDataFromImageSource等接口可以将ImageSource或pixelMap编码为file/data。
### 相关权限 ### 相关权限

View File

@ -7,7 +7,7 @@ set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${NATIVERENDER_ROOT_PATH} include_directories(${NATIVERENDER_ROOT_PATH}
${NATIVERENDER_ROOT_PATH}/include) ${NATIVERENDER_ROOT_PATH}/include)
add_library(entry SHARED hello.cpp) add_library(entry SHARED Image.cpp)
target_link_libraries(entry PUBLIC libace_napi.z.so) target_link_libraries(entry PUBLIC libace_napi.z.so)
target_link_libraries(entry PUBLIC libimage_source.so) target_link_libraries(entry PUBLIC libimage_source.so)
target_link_libraries(entry PUBLIC libimage_packer.so) target_link_libraries(entry PUBLIC libimage_packer.so)

View File

@ -242,13 +242,8 @@ static napi_value packToFileImageSource(napi_env env, napi_callback_info info)
} }
std::shared_ptr<OH_ImageSourceNative> ptrImgSource(imgSource, OH_ImageSourceNative_Release); std::shared_ptr<OH_ImageSourceNative> ptrImgSource(imgSource, OH_ImageSourceNative_Release);
auto ptrPixelMap = CreatePixelMap(ptrImgSource.get()); errCode = OH_ImagePackerNative_PackToFileFromImageSource(
if (!ptrPixelMap) { ptrPacker.get(), ptrOpts.get(), imgSource, outFD);
return retFailed;
}
errCode = OH_ImagePackerNative_PackToFileFromPixelmap(
ptrPacker.get(), ptrOpts.get(), ptrPixelMap.get(), outFD);
if (errCode != IMAGE_SUCCESS) { if (errCode != IMAGE_SUCCESS) {
return retFailed; return retFailed;
} }
@ -288,14 +283,11 @@ static napi_value packToDataImageSource(napi_env env, napi_callback_info info)
return retFailed; return retFailed;
} }
std::shared_ptr<OH_ImageSourceNative> ptrImgSource(imgSource, OH_ImageSourceNative_Release); std::shared_ptr<OH_ImageSourceNative> ptrImgSource(imgSource, OH_ImageSourceNative_Release);
auto ptrPixelMap = CreatePixelMap(ptrImgSource.get());
if (!ptrPixelMap) {
return retFailed;
}
uint8_t* outBuffer = new uint8_t[DEFAULT_BUFFER_SIZE]; uint8_t* outBuffer = new uint8_t[DEFAULT_BUFFER_SIZE];
size_t outBufferSize = 0; size_t outBufferSize = 0;
errCode = OH_ImagePackerNative_PackToDataFromPixelmap( errCode = OH_ImagePackerNative_PackToDataFromImageSource(
ptrPacker.get(), ptrOpts.get(), ptrPixelMap.get(), outBuffer, &outBufferSize); ptrPacker.get(), ptrOpts.get(), imgSource, outBuffer, &outBufferSize);
if (errCode != IMAGE_SUCCESS) { if (errCode != IMAGE_SUCCESS) {
delete [] outBuffer; delete [] outBuffer;
return retFailed; return retFailed;

View File

@ -15,7 +15,7 @@
{ {
"app": { "app": {
"bundleName": "com.samples.mindsporelite", "bundleName": "com.samples.mindsporelitearktsdemo",
"vendor": "samples", "vendor": "samples",
"versionCode": 1000000, "versionCode": 1000000,
"versionName": "1.0.0", "versionName": "1.0.0",

View File

@ -2,7 +2,7 @@
"string": [ "string": [
{ {
"name": "app_name", "name": "app_name",
"value": "MindSporeLite" "value": "MindSporeLiteArkTSDemo"
} }
] ]
} }

View File

@ -14,6 +14,12 @@
|-----------------------------------------------------| |-----------------------------------------------------|
| <img src="screenshots/MindSporeLiteArkTSDemo.png"/> | | <img src="screenshots/MindSporeLiteArkTSDemo.png"/> |
#### 使用说明
1. 在主界面可以点击photo按钮进入相册选择图片界面
2. 在相册界面,选择图片,点击确定按钮;
3. 自动进行选择图片的图像分类模型推理,部分推理结果显示在主界面。
### 工程目录 ### 工程目录
``` ```

View File

@ -26,6 +26,14 @@
"runtimeOS": "OpenHarmony" "runtimeOS": "OpenHarmony"
} }
], ],
"buildModeSet": [
{
"name": "debug",
},
{
"name": "release"
}
]
}, },
"modules": [ "modules": [
{ {

View File

@ -20,7 +20,8 @@
"description": "$string:module_desc", "description": "$string:module_desc",
"mainElement": "EntryAbility", "mainElement": "EntryAbility",
"deviceTypes": [ "deviceTypes": [
"default" "default",
"tablet"
], ],
"deliveryWithInstall": true, "deliveryWithInstall": true,
"installationFree": false, "installationFree": false,
@ -30,7 +31,7 @@
"name": "EntryAbility", "name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ets", "srcEntry": "./ets/entryability/EntryAbility.ets",
"description": "$string:EntryAbility_desc", "description": "$string:EntryAbility_desc",
"icon": "$media:layered_image", "icon": "$media:icon",
"label": "$string:EntryAbility_label", "label": "$string:EntryAbility_label",
"startWindowIcon": "$media:startIcon", "startWindowIcon": "$media:startIcon",
"startWindowBackground": "$color:start_window_background", "startWindowBackground": "$color:start_window_background",

View File

@ -10,7 +10,7 @@
}, },
{ {
"name": "EntryAbility_label", "name": "EntryAbility_label",
"value": "label" "value": "MindSporeLite"
} }
] ]
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -10,7 +10,7 @@
}, },
{ {
"name": "EntryAbility_label", "name": "EntryAbility_label",
"value": "label" "value": "MindSporeLite"
} }
] ]
} }

View File

@ -10,7 +10,7 @@
}, },
{ {
"name": "EntryAbility_label", "name": "EntryAbility_label",
"value": "label" "value": "MindSporeLite"
} }
] ]
} }

View File

@ -1,12 +0,0 @@
{
"devices": {
"general": [
"default"
]
},
"development": {
"addedSysCaps": [
"SystemCapability.AI.MindSporeLite"
]
}
}

View File

@ -0,0 +1,17 @@
/*
* Copyright (c) 2024 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.
*/
{
}

View File

@ -1,20 +1,19 @@
import { hilog } from '@kit.PerformanceAnalysisKit'; import { hilog } from '@kit.PerformanceAnalysisKit';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; import { describe, it, expect } from '@ohos/hypium';
import Want from '@ohos.app.ability.Want'; import Want from '@ohos.app.ability.Want';
import Base from '@ohos.base'; import Base from '@ohos.base';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import { Driver, ON, UIElementInfo, UIEventObserver } from '@ohos.UiTest'; import { Driver, ON } from '@ohos.UiTest';
import { getString } from '../utils/ResourceUtil'; import { getString } from '../utils/ResourceUtil';
const BUNDLE = 'MindSporeLiteArkTSDemo_'; const BUNDLE = 'MindSporeLiteArkTSDemo_';
const TAG = 'abilityTest'; const TAG = 'abilityTest';
const domain: number = 0xF811; const domain: number = 0xF811;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let resourceManager = abilityDelegator.getAppContext().resourceManager;
export default function abilityTest() { export default function abilityTest() {
let driver: Driver = Driver.create(); let driver: Driver = Driver.create();
describe('MindSporeLiteArkTSDemoTest', () => { describe('MindSporeLiteArkTSDemoTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
/* /*
* @tc.number: MindSporeLiteArkTSDemoTest_000 * @tc.number: MindSporeLiteArkTSDemoTest_000
* @tc.name: Start Ability * @tc.name: Start Ability
@ -23,11 +22,11 @@ export default function abilityTest() {
* @tc.type: Function * @tc.type: Function
* @tc.level Level 1 * @tc.level Level 1
*/ */
it(BUNDLE + 'EntryAbility', 0, async (done: Function) => { it('EntryAbility', 0, async (done: Function) => {
hilog.info(domain, TAG, BUNDLE + 'EntryAbility_001 begin'); hilog.info(domain, TAG, BUNDLE + 'EntryAbility_001 begin');
// 开启应用 // 开启应用
let want: Want = { let want: Want = {
bundleName: 'com.samples.mindsporelite', bundleName: 'com.samples.mindsporelitearktsdemo',
abilityName: 'EntryAbility' abilityName: 'EntryAbility'
}; };
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
@ -47,7 +46,7 @@ export default function abilityTest() {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 1 * @tc.level : Level 1
*/ */
it(BUNDLE + 'IfExists', 0, async (done: Function) => { it('IfExists', 0, async (done: Function) => {
hilog.info(domain, TAG, BUNDLE + 'IfExists_001 begin'); hilog.info(domain, TAG, BUNDLE + 'IfExists_001 begin');
await driver.delayMs(1000); await driver.delayMs(1000);
await driver.assertComponentExist(ON.text('MindSporeLite ArkTS Demo')); await driver.assertComponentExist(ON.text('MindSporeLite ArkTS Demo'));
@ -65,7 +64,7 @@ export default function abilityTest() {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 1 * @tc.level : Level 1
*/ */
it(BUNDLE + 'PhotoPredict', 0, async (done: Function) => { it('PhotoPredict', 0, async (done: Function) => {
hilog.info(domain, TAG, BUNDLE + 'PhotoPredict_001 begin'); hilog.info(domain, TAG, BUNDLE + 'PhotoPredict_001 begin');
await driver.delayMs(1000); await driver.delayMs(1000);
// 点击photo按钮 // 点击photo按钮

View File

@ -0,0 +1,47 @@
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { abilityDelegatorRegistry } from '@kit.TestKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
export default class TestAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.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) ?? '');
let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator;
abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator();
let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs;
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) => {
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.');
});
}
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');
}
}

View File

@ -0,0 +1,17 @@
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}

View File

@ -0,0 +1,90 @@
import { abilityDelegatorRegistry, TestRunner } from '@kit.TestKit';
import { UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { resourceManager } from '@kit.LocalizationKit';
import { util } from '@kit.ArkTS';
let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator;
let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs;
let jsonPath: string = 'mock/mock-config.json';
let tag: string = 'testTag';
async function onAbilityCreateCallback(data: UIAbility) {
hilog.info(0x0000, 'testTag', 'onAbilityCreateCallback, data: ${}', JSON.stringify(data));
}
async function addAbilityMonitorCallback(err: BusinessError) {
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() {
let tag = 'testTag';
hilog.info(0x0000, tag, '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = abilityDelegatorRegistry.getArguments()
abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator()
let moduleName = abilityDelegatorArguments.parameters['-m'];
let context = abilityDelegator.getAppContext().getApplicationContext().createModuleContext(moduleName);
let mResourceManager = context.resourceManager;
await checkMock(abilityDelegator, mResourceManager);
const bundleName = abilityDelegatorArguments.bundleName;
const testAbilityName: string = 'TestAbility';
let lMonitor: abilityDelegatorRegistry.AbilityMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
moduleName: moduleName
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
const want: Want = {
bundleName: bundleName,
abilityName: testAbilityName,
moduleName: moduleName
};
abilityDelegator.startAbility(want, (err: BusinessError, data: void) => {
hilog.info(0x0000, tag, 'startAbility : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, tag, 'startAbility : data : %{public}s', JSON.stringify(data) ?? '');
})
hilog.info(0x0000, tag, '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
async function checkMock(abilityDelegator: abilityDelegatorRegistry.AbilityDelegator, resourceManager: resourceManager.ResourceManager) {
let rawFile: Uint8Array;
try {
rawFile = resourceManager.getRawFileContentSync(jsonPath);
hilog.info(0x0000, tag, 'MockList file exists');
let mockStr: string = util.TextDecoder.create("utf-8", { ignoreBOM: true }).decodeWithStream(rawFile);
let mockMap: Record<string, string> = getMockList(mockStr);
try {
abilityDelegator.setMockList(mockMap)
} catch (error) {
let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
hilog.error(0x0000, tag, `abilityDelegator.setMockList failed, error code: ${code}, message: ${message}.`);
}
} catch (error) {
let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
hilog.error(0x0000, tag, `ResourceManager:callback getRawFileContent failed, error code: ${code}, message: ${message}.`);
}
}
function getMockList(jsonStr: string) {
let jsonObj: Record<string, Object> = JSON.parse(jsonStr);
let map: Map<string, object> = new Map<string, object>(Object.entries(jsonObj));
let mockList: Record<string, string> = {};
map.forEach((value: object, key: string) => {
let realValue: string = value['source'].toString();
mockList[key] = realValue;
});
hilog.info(0x0000, tag, '%{public}s', 'mock-json value:' + JSON.stringify(mockList) ?? '');
return mockList;
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2023 Huawei Device Co., Ltd. * Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. * Copyright (c) 2024 Hunan OpenValley Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -17,11 +17,36 @@
"module": { "module": {
"name": "entry_test", "name": "entry_test",
"type": "feature", "type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [ "deviceTypes": [
"default", "default",
"tablet" "tablet"
], ],
"deliveryWithInstall": true, "deliveryWithInstall": true,
"installationFree": false "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"
]
}
]
}
]
} }
} }

View File

@ -0,0 +1,8 @@
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}

View File

@ -1,7 +1,7 @@
{ {
"string": [ "string": [
{ {
"name": "entry_test_desc", "name": "module_test_desc",
"value": "test ability description" "value": "test ability description"
}, },
{ {
@ -15,98 +15,6 @@
{ {
"name": "completed", "name": "completed",
"value": "完成" "value": "完成"
},
{
"name": "crop",
"value": "裁剪"
},
{
"name": "percent43",
"value": "4:3"
},
{
"name": "percent169",
"value": "16:9"
},
{
"name": "percent11",
"value": "1:1"
},
{
"name": "origin",
"value": "原图"
},
{
"name": "rotate",
"value": "旋转"
},
{
"name": "scale",
"value": "缩放"
},
{
"name": "zoomIn",
"value": "放大"
},
{
"name": "zoomOut",
"value": "缩小"
},
{
"name": "mark",
"value": "标记"
},
{
"name": "sticker",
"value": "贴纸"
},
{
"name": "text",
"value": "文字"
},
{
"name": "toning",
"value": "调色"
},
{
"name": "colorSpaceAdobeRGB",
"value": "ADOBE_RGB"
},
{
"name": "colorSpaceDCIP3",
"value": "DCI_P3"
},
{
"name": "colorSpaceDisplayP3",
"value": "DisplayP3"
},
{
"name": "colorSpaceSRGB",
"value": "SRGB"
},
{
"name": "colorSpace",
"value": "色域"
},
{
"name": "takePhoto",
"value": "拍照"
},
{
"name": "setting",
"value": "修改hdr设置"
},
{
"name": "auto",
"value": "自动"
},
{
"name": "sdr",
"value": "SDR"
},
{
"name": "hdr",
"value": "HDR"
} }
] ]
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -0,0 +1,5 @@
{
"src": [
"testability/pages/Index"
]
}

View File

@ -0,0 +1,5 @@
import localUnitTest from './LocalUnit.test';
export default function testsuite() {
localUnitTest();
}

View File

@ -0,0 +1,33 @@
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function localUnitTest() {
describe('localUnitTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
});
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
});
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
});
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
});
it('assertContain', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let a = 'abc';
let b = 'b';
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
});
});
}

View File

@ -13,13 +13,13 @@
* limitations under the License. * limitations under the License.
*/ */
{ {
"modelVersion": "5.0.0", "hvigorVersion": "4.1.2",
"dependencies": { "dependencies": {
"@ohos/hvigor-ohos-plugin": "4.1.2"
}, },
"execution": { "execution": {
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */
// "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */
// "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */
// "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */

View File

@ -14,8 +14,7 @@
*/ */
{ {
"modelVersion": "5.0.0", "name": "mindsporelitearktsdemo",
"name": "myapplicationarktsdemo",
"version": "1.0.0", "version": "1.0.0",
"description": "Please describe the basic information.", "description": "Please describe the basic information.",
"main": "", "main": "",
@ -24,7 +23,7 @@
"dependencies": { "dependencies": {
}, },
"devDependencies": { "devDependencies": {
"@ohos/hypium": "1.0.17", "@ohos/hypium": "1.0.16",
"@ohos/hamock": "1.0.1-rc2" "@ohos/hamock": "1.0.0"
} }
} }

View File

@ -115,6 +115,7 @@ struct DataPanelSample {
path.lineTo(25, 105); path.lineTo(25, 105);
path.lineTo(75, 105); path.lineTo(75, 105);
path.lineTo(75, 25); path.lineTo(75, 25);
path.lineTo(25, 25);
this.context.strokeStyle = 'rgb(0,0,255)'; this.context.strokeStyle = 'rgb(0,0,255)';
this.context.stroke(path); this.context.stroke(path);
this.context.restore(); this.context.restore();