未验证 提交 fd6b7aa1 编写于 作者: O openharmony_ci 提交者: Gitee

!7754 add imageReceiverNdk testcase

Merge pull request !7754 from caochuan/receiverNdk
......@@ -41,6 +41,7 @@ group("multimedia") {
"image/image_js_standard/imageRGBA:image_rgba_js_hap",
"image/image_js_standard/imageRaw:image_raw_js_hap",
"image/image_js_standard/imageReceiver:image_receiver_js_hap",
"image/image_js_standard/imageReceiverNDK:image_receiver_ndk_js_hap",
"image/image_js_standard/imageSvg:image_svg_js_hap",
"image/image_js_standard/imageWebp:image_webp_js_hap",
"image/image_js_standard/imageYUV:image_yuv_js_hap",
......
# 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.gni")
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("image_receiver_ndk_js_hap") {
hap_profile = "./entry/src/main/config.json"
deps = [
":ace_third_ets_assets",
":ace_third_ets_resources",
":ace_third_ets_test_assets",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsImageReceiverNdkJsTest"
subsystem_name = "multimedia"
part_name = "multimedia_image_framework"
shared_libraries = [ "./entry/src/main/cpp:ImageReceiverNDKTest" ]
}
ohos_js_assets("ace_third_ets_assets") {
source_dir = "./entry/src/main/ets/MainAbility"
}
ohos_js_assets("ace_third_ets_test_assets") {
source_dir = "./entry/src/main/ets/TestAbility"
}
ohos_resources("ace_third_ets_resources") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"testcase-timeout": "300000",
"bundle-name": "ohos.acts.multimedia.image.ReceiverNdk",
"package-name": "ohos.acts.multimedia.image.ReceiverNdk",
"shell-timeout": "600000"
},
"kits": [
{
"test-file-name": [
"ActsImageReceiverNdkJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.multimedia.image.ReceiverNdk",
"vendor": "open",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 9,
"releaseType": "Release",
"target": 9
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.multimedia.image.ReceiverNdk",
"name": ".MyApplication",
"mainAbility": "ohos.acts.multimedia.image.ReceiverNdk.MainAbility",
"deviceType": [
"tablet",
"default",
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"reqPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO",
"reason": "use ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason": "use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
"name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason": "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
},
{
"name": "ohos.permission.MEDIA_LOCATION",
"reason": "use ohos.permission.MEDIA_LOCATION"
},
{
"name": "ohos.permission.READ_MEDIA",
"reason": "use ohos.permission.READ_MEDIA"
},
{
"name": "ohos.permission.WRITE_MEDIA",
"reason": "use ohos.permission.WRITE_MEDIA"
}
],
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_mainability",
"formsEnabled": false,
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
},
{
"orientation": "unspecified",
"visible": true,
"srcPath": "TestAbility",
"name": ".TestAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"formsEnabled": false,
"label": "$string:TestAbility_label",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
\ 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("//build/config/ohos/config.gni")
import("//build/ohos.gni")
import("//foundation/arkui/napi/napi.gni")
config("config") {
visibility = [ ":*" ]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Wunused-variable",
]
}
ohos_shared_library("ImageReceiverNDKTest") {
sources = [ "./napi/image_receiver_mdk_test.cpp" ]
if (target_cpu == "arm") {
libs = [ "${clang_base_path}/../libcxx-ndk/lib/arm-linux-ohos/c++/libc++_shared.so" ]
} else if (target_cpu == "arm64") {
libs = [ "${clang_base_path}/../libcxx-ndk/lib/aarch64-linux-ohos/c++/libc++_shared.so" ]
} else {
libs = []
}
include_dirs = [ "../cpp" ]
configs = [ ":config" ]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"multimedia_image_framework:image_ndk",
"multimedia_image_framework:image_receiver_ndk",
"napi:ace_napi",
]
output_extension = "so"
subsystem_name = "multimedia"
part_name = "multimedia_image_framework"
}
/*
* 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.
*/
#include "image_receiver_mdk_test.h"
#include "node_api.h"
#include <string>
#include "hilog/log.h"
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD002B05, "ImageReceiverNDKTest"};
}
namespace {
constexpr uint32_t NUM_0 = 0;
constexpr uint32_t NUM_1 = 1;
constexpr uint32_t NUM_2 = 2;
constexpr uint32_t NUM_3 = 3;
constexpr uint32_t NUM_4 = 4;
constexpr size_t ID_SIZE = 64;
}
namespace OHOS {
namespace Media {
#define STATIC_FUNCTION(n, f) { (n), nullptr, (f), nullptr, nullptr, nullptr, napi_static, nullptr }
uint32_t ImageReceiverNDKTest::sOnEvnentCount = 0;
napi_value ImageReceiverNDKTest::Init(napi_env env, napi_value exports)
{
napi_property_descriptor props[] = {
STATIC_FUNCTION("createImageReceiver", JsCreateImageReceiver),
STATIC_FUNCTION("getReceivingSurfaceId", JsGetReceivingSurfaceId),
STATIC_FUNCTION("readLatestImage", JsReadLatestImage),
STATIC_FUNCTION("readNextImage", JsReadNextImage),
STATIC_FUNCTION("on", JsOn),
STATIC_FUNCTION("getSize", JsGetSize),
STATIC_FUNCTION("getCapacity", JsGetCapacity),
STATIC_FUNCTION("getFormat", JsGetFormat),
STATIC_FUNCTION("getOnEventCount", JsGetOnEventCount),
STATIC_FUNCTION("imageClipRect", JsImageClipRect),
STATIC_FUNCTION("imageSize", JsImageSize),
STATIC_FUNCTION("imageFormat", JsImageFormat),
STATIC_FUNCTION("imageGetComponent", JsImageGetComponent),
};
napi_define_properties(env, exports, sizeof(props) / sizeof(props[0]), props);
return exports;
}
static bool CheckArgs(size_t count, napi_value* argValues, size_t exceptCount)
{
if (count != exceptCount) {
return false;
}
for (size_t i = NUM_0; i < count; i++) {
if (argValues[i] == nullptr) {
return false;
}
}
return true;
}
napi_value ImageReceiverNDKTest::JsCreateImageReceiver(napi_env env, napi_callback_info info)
{
napi_value udfVar = nullptr;
napi_value thisVar = nullptr;
napi_value argValue[NUM_4] = {0};
size_t argCount = NUM_4;
struct OhosImageReceiverInfo receiverInfo;
napi_value receiver = nullptr;
napi_get_undefined(env, &udfVar);
if (napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr) != napi_ok ||
!CheckArgs(argCount, argValue, NUM_4) ||
napi_get_value_int32(env, argValue[NUM_0], &(receiverInfo.width)) != napi_ok ||
napi_get_value_int32(env, argValue[NUM_1], &(receiverInfo.height)) != napi_ok ||
napi_get_value_int32(env, argValue[NUM_2], &(receiverInfo.format)) != napi_ok ||
napi_get_value_int32(env, argValue[NUM_3], &(receiverInfo.capicity)) != napi_ok) {
return udfVar;
}
int32_t res = OH_Image_Receiver_CreateImageReceiver(env, receiverInfo, &receiver);
if (res != OHOS_IMAGE_RESULT_SUCCESS || receiver == nullptr) {
return udfVar;
}
return receiver;
}
static ImageReceiverNative* getNativeReceiver(napi_env env, napi_callback_info info)
{
napi_value thisVar = nullptr;
napi_value argValue[NUM_1] = {0};
size_t argCount = NUM_1;
if (napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr) != napi_ok ||
argCount < NUM_1 || argValue[NUM_0] == nullptr) {
return nullptr;
}
return OH_Image_Receiver_InitImageReceiverNative(env, argValue[NUM_0]);
}
napi_value ImageReceiverNDKTest::JsGetReceivingSurfaceId(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_get_undefined(env, &result);
ImageReceiverNative* native = getNativeReceiver(env, info);
if (native == nullptr) {
return result;
}
char buf[ID_SIZE] = {0};
int32_t res = OH_Image_Receiver_GetReceivingSurfaceId(native, buf, ID_SIZE);
if (res != OHOS_IMAGE_RESULT_SUCCESS) {
return result;
}
HiviewDFX::HiLog::Debug(LABEL, "JsGetReceivingSurfaceId IN [%{public}x]", buf[0]);
HiviewDFX::HiLog::Debug(LABEL, "JsGetReceivingSurfaceId IN [%{public}c]", *buf);
HiviewDFX::HiLog::Debug(LABEL, "JsGetReceivingSurfaceId IN [%{public}s]", buf);
napi_create_string_utf8(env, buf, NAPI_AUTO_LENGTH, &result);
return result;
}
napi_value ImageReceiverNDKTest::JsReadLatestImage(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_get_undefined(env, &result);
ImageReceiverNative* native = getNativeReceiver(env, info);
if (native == nullptr) {
return result;
}
int32_t res = OH_Image_Receiver_ReadLatestImage(native, &result);
if (res != OHOS_IMAGE_RESULT_SUCCESS) {
napi_get_undefined(env, &result);
return result;
}
return result;
}
napi_value ImageReceiverNDKTest::JsReadNextImage(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_get_undefined(env, &result);
ImageReceiverNative* native = getNativeReceiver(env, info);
if (native == nullptr) {
return result;
}
int32_t res = OH_Image_Receiver_ReadNextImage(native, &result);
if (res != OHOS_IMAGE_RESULT_SUCCESS) {
napi_get_undefined(env, &result);
return result;
}
return result;
}
void ImageReceiverNDKTest::OnEvent()
{
HiviewDFX::HiLog::Debug(LABEL, "ImageReceiverNDKTest::OnEvent IN [%{public}p]", &sOnEvnentCount);
sOnEvnentCount++;
}
napi_value ImageReceiverNDKTest::JsOn(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_get_undefined(env, &result);
ImageReceiverNative* native = getNativeReceiver(env, info);
if (native == nullptr) {
return result;
}
sOnEvnentCount = NUM_0;
int32_t res = OH_Image_Receiver_On(native, OnEvent);
napi_create_int32(env, res, &result);
return result;
}
static void setInt32NamedProperty(napi_env env, napi_value object, const char* utf8name, int32_t value)
{
napi_value tmp;
napi_create_int32(env, value, &tmp);
napi_set_named_property(env, object, utf8name, tmp);
}
static void setByteArrayNamedProperty(napi_env env, napi_value object,
const char* utf8name, uint8_t* buffer, size_t size)
{
napi_value tmp;
napi_create_external_arraybuffer(env, buffer, size,
[](napi_env env, void* data, void* hint) { }, nullptr, &tmp);
napi_set_named_property(env, object, utf8name, tmp);
}
napi_value ImageReceiverNDKTest::JsGetSize(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_get_undefined(env, &result);
ImageReceiverNative* native = getNativeReceiver(env, info);
if (native == nullptr) {
return result;
}
struct OhosImageSize size;
int32_t res = OH_Image_Receiver_GetSize(native, &size);
if (res != OHOS_IMAGE_RESULT_SUCCESS) {
return result;
}
napi_create_object(env, &result);
setInt32NamedProperty(env, result, "width", size.width);
setInt32NamedProperty(env, result, "height", size.height);
return result;
}
napi_value ImageReceiverNDKTest::JsGetCapacity(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_get_undefined(env, &result);
ImageReceiverNative* native = getNativeReceiver(env, info);
if (native == nullptr) {
return result;
}
int32_t capacity;
int32_t res = OH_Image_Receiver_GetCapacity(native, &capacity);
if (res != OHOS_IMAGE_RESULT_SUCCESS) {
return result;
}
napi_create_int32(env, capacity, &result);
return result;
}
napi_value ImageReceiverNDKTest::JsGetFormat(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_get_undefined(env, &result);
ImageReceiverNative* native = getNativeReceiver(env, info);
if (native == nullptr) {
return result;
}
int32_t format;
int32_t res = OH_Image_Receiver_GetFormat(native, &format);
if (res != OHOS_IMAGE_RESULT_SUCCESS) {
return result;
}
napi_create_int32(env, format, &result);
return result;
}
napi_value ImageReceiverNDKTest::JsGetOnEventCount(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_create_uint32(env, sOnEvnentCount, &result);
return result;
}
static ImageNative* getNativeImage(napi_env env, napi_callback_info info)
{
napi_value thisVar = nullptr;
napi_value argValue[NUM_1] = {0};
size_t argCount = NUM_1;
if (napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr) != napi_ok ||
argCount < NUM_1 || argValue[NUM_0] == nullptr) {
return nullptr;
}
return OH_Image_InitImageNative(env, argValue[NUM_0]);
}
napi_value ImageReceiverNDKTest::JsImageClipRect(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_get_undefined(env, &result);
ImageNative* native = getNativeImage(env, info);
if (native == nullptr) {
return result;
}
struct OhosImageRect rect;
int32_t res = OH_Image_ClipRect(native, &rect);
if (res != OHOS_IMAGE_RESULT_SUCCESS) {
return result;
}
napi_create_object(env, &result);
setInt32NamedProperty(env, result, "x", rect.x);
setInt32NamedProperty(env, result, "y", rect.y);
setInt32NamedProperty(env, result, "width", rect.width);
setInt32NamedProperty(env, result, "height", rect.height);
return result;
}
napi_value ImageReceiverNDKTest::JsImageSize(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_get_undefined(env, &result);
ImageNative* native = getNativeImage(env, info);
if (native == nullptr) {
return result;
}
struct OhosImageSize size;
int32_t res = OH_Image_Size(native, &size);
if (res != OHOS_IMAGE_RESULT_SUCCESS) {
return result;
}
napi_create_object(env, &result);
setInt32NamedProperty(env, result, "width", size.width);
setInt32NamedProperty(env, result, "height", size.height);
return result;
}
napi_value ImageReceiverNDKTest::JsImageFormat(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_get_undefined(env, &result);
ImageNative* native = getNativeImage(env, info);
if (native == nullptr) {
return result;
}
int32_t format;
int32_t res = OH_Image_Format(native, &format);
if (res != OHOS_IMAGE_RESULT_SUCCESS) {
return result;
}
napi_create_uint32(env, format, &result);
return result;
}
napi_value ImageReceiverNDKTest::JsImageGetComponent(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_value thisVar = nullptr;
napi_value argValue[NUM_2] = {0};
size_t argCount = NUM_2;
napi_get_undefined(env, &result);
if (napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr) != napi_ok ||
!CheckArgs(argCount, argValue, NUM_2)) {
return result;
}
ImageNative* native = OH_Image_InitImageNative(env, argValue[NUM_0]);
if (native == nullptr) {
return result;
}
int32_t componentType;
napi_get_value_int32(env, argValue[NUM_1], &componentType);
struct OhosImageComponent component;
int32_t res = OH_Image_GetComponent(native, componentType, &component);
if (res != OHOS_IMAGE_RESULT_SUCCESS) {
return result;
}
napi_create_object(env, &result);
HiviewDFX::HiLog::Debug(LABEL, "ImageReceiverNDKTest::JsImageGetComponent IN [%{public}p]", component.byteBuffer);
HiviewDFX::HiLog::Debug(LABEL, "ImageReceiverNDKTest::JsImageGetComponent IN [%{public}d]", component.size);
setByteArrayNamedProperty(env, result, "byteBuffer", component.byteBuffer, component.size);
setInt32NamedProperty(env, result, "componentType", component.componentType);
setInt32NamedProperty(env, result, "rowStride", component.rowStride);
setInt32NamedProperty(env, result, "pixelStride", component.pixelStride);
return result;
}
EXTERN_C_START
napi_value ModuleRegister(napi_env env, napi_value exports)
{
ImageReceiverNDKTest::Init(env, exports);
return exports;
}
static napi_module demoModule = {
.nm_version =1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = ModuleRegister,
.nm_modname = "ImageReceiverNDKTest",
.nm_priv = ((void*)0),
.reserved = { 0 },
};
__attribute__((constructor)) void RegisterModule(void)
{
napi_module_register(&demoModule);
}
EXTERN_C_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.
*/
#ifndef IMAGE_RECEIVER_MDK_TEST_H
#define IMAGE_RECEIVER_MDK_TEST_H
#include <memory>
#include <string>
#include "napi/native_api.h"
#include "image_receiver_mdk.h"
namespace OHOS {
namespace Media {
class ImageReceiverNDKTest {
public:
static napi_value Init(napi_env env, napi_value exports);
static napi_value JsCreateImageReceiver(napi_env env, napi_callback_info info);
static napi_value JsGetReceivingSurfaceId(napi_env env, napi_callback_info info);
static napi_value JsReadLatestImage(napi_env env, napi_callback_info info);
static napi_value JsReadNextImage(napi_env env, napi_callback_info info);
static napi_value JsOn(napi_env env, napi_callback_info info);
static napi_value JsGetSize(napi_env env, napi_callback_info info);
static napi_value JsGetCapacity(napi_env env, napi_callback_info info);
static napi_value JsGetFormat(napi_env env, napi_callback_info info);
static napi_value JsGetOnEventCount(napi_env env, napi_callback_info info);
static napi_value JsImageClipRect(napi_env env, napi_callback_info info);
static napi_value JsImageSize(napi_env env, napi_callback_info info);
static napi_value JsImageFormat(napi_env env, napi_callback_info info);
static napi_value JsImageGetComponent(napi_env env, napi_callback_info info);
private:
static uint32_t sOnEvnentCount;
static void OnEvent();
};
} // namespace Media
} // namespace OHOS
#endif // IMAGE_RECEIVER_MDK_TEST_H
\ No newline at end of file
// @ts-nocheck
/**
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from 'hypium/index'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('Application onCreate')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info('Application onDestroy')
},
}
\ No newline at end of file
// @ts-nocheck
/**
* 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 MyComponent {
aboutToAppear() {
}
build() {
Flex({
direction: FlexDirection.Column,
alignItems: ItemAlign.Center,
justifyContent: FlexAlign.Center
}) {
Text('ACE ETS TEST')
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
.height('100%')
}
}
// @ts-nocheck
/**
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from 'hypium/index'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('Application onCreate')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info('Application onDestroy')
},
}
\ No newline at end of file
// @ts-nocheck
/**
* 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 router from '@system.router';
@Entry
@Component
struct Index {
aboutToAppear() {
console.info('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
// @ts-nocheck
/**
* 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 TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
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')
}
onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.MainAbility'
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -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 call abilityDelegator.getAppContext')
var context = abilityDelegator.getAppContext()
console.info('getAppContext : ' + JSON.stringify(context))
console.info('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 ImageReceiverNDKTest from './receiverNDK.test.ets';
export default function testsuite() {
ImageReceiverNDKTest()
}
\ No newline at end of file
// @ts-nocheck
/*
* 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 image from "@ohos.multimedia.image";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index'
import ndkTest from 'libImageReceiverNDKTest.so'
export default function ImageReceiverNDKTest() {
describe('ImageReceiverNDKTest', function () {
const WIDTH = 8192;
const HEIGHT = 8;
const CAPACITY = 8;
const RGBA = 12;
const Jpg_Stride = 1;
const RECEIVER_FORMAT = 2000;
const { JPEG } = image.ComponentType;
function logger(caseName) {
return {
myName: caseName,
log: function (msg) {
console.info(this.myName + ' ' + msg);
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
beforeAll(function () { console.info('beforeAll case'); })
beforeEach(function () { console.info('beforeEach case'); })
afterEach(function () { console.info('afterEach case'); })
afterAll(function () { console.info('afterAll case'); })
function createReceiverErr(done, log, ...params) {
let mlg = logger(log);
try {
mlg.log(log);
let myReceiver = ndkTest.createImageReceiver(params);
expect(myReceiver == undefined).assertTrue();
done();
} catch (error) {
mlg.log("Test exception " + error);
expect().assertFail();
done();
}
}
function isString(value) {
return typeof value === "string";
}
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_0100
* @tc.name : createImageReceiver
* @tc.desc : 1.set width,height,format,capacity
* : 2.createImageReceiver
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_0100', 0, async function (done) {
let mlg = logger("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0100");
try {
mlg.log("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0100");
let myReceiver = ndkTest.createImageReceiver(WIDTH, HEIGHT, RECEIVER_FORMAT, CAPACITY);
expect(myReceiver != undefined).assertTrue();
done();
} catch (error) {
mlg.log("Test exception " + error);
expect().assertFail();
done();
}
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0100
* @tc.name : createImageReceiver
* @tc.desc : 1.set width,height,format,capacity
* : 2.createImageReceiver
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0100', 0, async function (done) {
createReceiverErr(done, "SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0100", 'a', HEIGHT, RECEIVER_FORMAT, CAPACITY);
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0200
* @tc.name : createImageReceiver
* @tc.desc : 1.set width,height,format,capacity
* : 2.createImageReceiver
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0200', 0, async function (done) {
createReceiverErr(done, "SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0200", WIDTH, { a: 1 }, RECEIVER_FORMAT,
CAPACITY);
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0300
* @tc.name : createImageReceiver
* @tc.desc : 1.set width,height,format,capacity
* : 2.createImageReceiver
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0300', 0, async function (done) {
createReceiverErr(done, "SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0300", WIDTH, HEIGHT, null, CAPACITY);
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0400
* @tc.name : createImageReceiver
* @tc.desc : 1.set width,height,format,capacity
* : 2.createImageReceiver
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0400', 0, async function (done) {
createReceiverErr(done, "SUB_GRAPHIC_IMAGE_RECEIVERNDK_ERR_0400", WIDTH, HEIGHT, RECEIVER_FORMAT, true);
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_0200
* @tc.name : createImageReceiver
* @tc.desc : 1.set width,height,format,capacity
* : 2.createImageReceiver
* : 3.getSize,getFormat,getCapacity
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_0200', 0, async function (done) {
let mlg = logger("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0200");
try {
mlg.log("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0200");
let myReceiver = ndkTest.createImageReceiver(WIDTH, HEIGHT, RECEIVER_FORMAT, CAPACITY);
let size = ndkTest.getSize(myReceiver);
let capacity = ndkTest.getCapacity(myReceiver);
let format = ndkTest.getFormat(myReceiver);
expect(size.width == WIDTH).assertTrue();
expect(size.height == HEIGHT).assertTrue();
expect(capacity == CAPACITY).assertTrue();
expect(format == RECEIVER_FORMAT).assertTrue();
done();
} catch (error) {
mlg.log("Test exception " + error);
expect().assertFail();
done();
}
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_0300
* @tc.name : getReceivingSurfaceId
* @tc.desc : 1.createImageReceiver
* : 2.getReceivingSurfaceId
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_0300', 0, async function (done) {
let mlg = logger("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0300");
try {
mlg.log("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0300");
let myReceiver = ndkTest.createImageReceiver(WIDTH, HEIGHT, RECEIVER_FORMAT, CAPACITY);
let sId = ndkTest.getReceivingSurfaceId(myReceiver);
mlg.log("sId " + sId);
expect(isString(sId)).assertTrue();
done();
} catch (error) {
mlg.log("Test exception " + error);
expect().assertFail();
done();
}
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_0400
* @tc.name : readLatestImage
* @tc.desc : 1.createImageReceiver
* : 2.readLatestImage
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_0400', 0, async function (done) {
let mlg = logger("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0400");
try {
mlg.log("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0400");
let myReceiver = ndkTest.createImageReceiver(WIDTH, HEIGHT, RECEIVER_FORMAT, CAPACITY);
var dummy = myReceiver.test;
let myLatestImage = ndkTest.readLatestImage(myReceiver);
mlg.log("myLatestImage " + JSON.stringify(myLatestImage));
expect(myLatestImage != undefined).assertTrue();
done();
} catch (error) {
mlg.log("Test exception " + error);
expect().assertFail();
done();
}
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_0500
* @tc.name : readNextImage
* @tc.desc : 1.createImageReceiver
* : 2.readNextImage
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_0500', 0, async function (done) {
let mlg = logger("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0500");
try {
mlg.log("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0500");
let myReceiver = ndkTest.createImageReceiver(WIDTH, HEIGHT, RECEIVER_FORMAT, CAPACITY);
var dummy = myReceiver.test;
let myNextImage = ndkTest.readNextImage(myReceiver);
mlg.log("myNextImage " + JSON.stringify(myNextImage));
expect(myNextImage != undefined).assertTrue();
done();
} catch (error) {
mlg.log("Test exception " + error);
expect().assertFail();
done();
}
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_0600
* @tc.name : on
* @tc.desc : 1.createImageReceiver
* : 2.on
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_0600', 0, async function (done) {
let mlg = logger("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0600");
try {
mlg.log("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0600");
let myReceiver = ndkTest.createImageReceiver(WIDTH, HEIGHT, RECEIVER_FORMAT, CAPACITY);
let onRet = ndkTest.on(myReceiver);
mlg.log("onRet " + JSON.stringify(onRet));
var dummy = myReceiver.test;
await sleep(2000);
expect(onRet != undefined).assertTrue();
done();
} catch (error) {
mlg.log("Test exception " + error);
expect().assertFail();
done();
}
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_0700
* @tc.name : getOnEventCount
* @tc.desc : 1.createImageReceiver
* : 2.on
* : 3.getOnEventCount
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_0700', 0, async function (done) {
let mlg = logger("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0700");
try {
mlg.log("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0700");
let myReceiver = ndkTest.createImageReceiver(WIDTH, HEIGHT, RECEIVER_FORMAT, CAPACITY);
let onRet = ndkTest.on(myReceiver);
mlg.log("onRet " + JSON.stringify(onRet));
expect(onRet != undefined).assertTrue();
var dummy = myReceiver.test;
mlg.log("dummy test !!! ");
let loop = 5;
let onCount = 0;
while (loop > 0) {
onCount = ndkTest.getOnEventCount(myReceiver);
mlg.log("onCount " + JSON.stringify(onCount));
if (onCount > 0) {
break;
}
await sleep(500);
loop--;
}
if (onCount == 0) {
expect(false).assertTrue();
done();
return;
}
expect(true).assertTrue();
done();
} catch (error) {
mlg.log("Test exception " + error);
expect().assertFail();
done();
}
})
/**
* @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_0800
* @tc.name : imageGetComponent
* @tc.desc : 1.createImageReceiver
* : 2.on
* : 3.imageGetComponent
* @tc.size : MEDIUM
* @tc.type : Functional
* @tc.level : Level 0
*/
it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_0800', 0, async function (done) {
let mlg = logger("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0800");
try {
mlg.log("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0800");
let myReceiver = ndkTest.createImageReceiver(WIDTH, HEIGHT, RECEIVER_FORMAT, CAPACITY);
let onRet = ndkTest.on(myReceiver);
mlg.log("onRet " + JSON.stringify(onRet));
expect(onRet != undefined).assertTrue();
var dummy = myReceiver.test;
mlg.log("dummy test !!! ")
let myLatestImage = ndkTest.readLatestImage(myReceiver);
let myImageClipRect = ndkTest.imageClipRect(myLatestImage);
let myImageSize = ndkTest.imageSize(myLatestImage);
let myImageFormat = ndkTest.imageFormat(myLatestImage);
let myImageComponent = ndkTest.imageGetComponent(myLatestImage, JPEG);
var bufferArr = new Uint8Array(myImageComponent.byteBuffer);
mlg.log("myImageComponent.byteBuffer size " + JSON.stringify(bufferArr.length));
for (var i = 0; i < 30; i++) {
mlg.log("myImageComponent.byteBuffer data " + JSON.stringify(bufferArr[i]));
}
expect(myImageClipRect != undefined).assertTrue();
expect(myImageSize.width == WIDTH && myImageSize.height == HEIGHT).assertTrue();
expect(myImageFormat == RGBA).assertTrue();
expect(myImageComponent.byteBuffer != undefined).assertTrue();
expect(myImageComponent.componentType == JPEG).assertTrue();
expect(myImageComponent.rowStride == WIDTH / Jpg_Stride).assertTrue();
expect(myImageComponent.pixelStride == Jpg_Stride).assertTrue();
done();
} catch (error) {
mlg.log("Test exception " + error);
expect().assertFail();
done();
}
})
})
}
\ No newline at end of file
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
},
{
"name": "description_mainability",
"value": "ETS_Empty Ability"
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册