提交 2485df98 编写于 作者: 戴伟琦

codec用例上库

Signed-off-by: N戴伟琦 <daiweiqi@huawei.com>
上级 afc3e8c4
......@@ -30,7 +30,6 @@ group("multimedia") {
"audio/audio_js_standard/audio_ndk_test:audioDemo_ndk_hap",
"avsession/avsession_js_standard/avsessionManager:avsession_framework_js_hap",
"camera/camera_js_standard:camera_framework_ets_hap",
"image/image_js_standard/crossplatform/image:ActsCrossplatformImageTest",
"image/image_js_standard/image:image_js_hap",
"image/image_js_standard/imageColorspace:image_colorspace_js_hap",
"image/image_js_standard/imageCreator:image_creator_js_hap",
......@@ -57,8 +56,8 @@ group("multimedia") {
"media/media_js_standard/audioRecorder:audio_recorder_js_hap",
"media/media_js_standard/avPlayer:avplayer_js_hap",
"media/media_js_standard/avRecorder:av_recorder_js_hap",
"media/media_js_standard/codec_ndk_test:codecDemo_ndk_hap",
"media/media_js_standard/recorderFormat:recorder_format_js_hap",
"media/media_js_standard/screenCapture_ndk_test:screenCapture_xts_ndk_hap",
"media/media_js_standard/videoPlayer:video_player_js_hap",
"medialibrary/mediaLibrary_album:mediaLibrary_album_hap",
"medialibrary/mediaLibrary_base:mediaLibrary_base_hap",
......
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test
\ 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("//test/xts/tools/build/suite.gni")
ohos_js_app_suite("codecDemo_ndk_hap") {
test_hap = true
testonly = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsAvCodecTest"
part_name = "av_codec"
subsystem_name = "multimedia"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"shell-timeout": "180000",
"bundle-name": "com.example.myapplication",
"package-name": "com.example.myapplication_test"
},
"kits": [
{
"test-file-name": [
"ActsAvCodecTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
},{
"type": "ShellKit",
"run-command": [
"power-shell wakeup",
"power-shell setmode 602"
]
}
]
}
\ No newline at end of file
{
"app": {
"signingConfigs": [
],
"compileSdkVersion": 10,
"compatibleSdkVersion": 10,
"products": [
{
"name": "default",
"signingConfig": "default",
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
\ No newline at end of file
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
\ No newline at end of file
{
"apiType": 'faMode',
"buildOption": {
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt",
"arguments": "",
"cppFlags": "",
}
},
"targets": [
{
"name": "default",
},
{
"name": "ohosTest",
}
]
}
\ No newline at end of file
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
export { legacyHapTasks } from '@ohos/hvigor-ohos-plugin';
{
"license": "",
"devDependencies": {
"@types/libentry.so": "file:./src/main/cpp/types/libentry"
},
"author": "",
"name": "entry",
"description": "Please describe the basic information.",
"main": "",
"version": "1.0.0",
"dependencies": {}
}
{
"app": {
"bundleName": "com.example.myapplication",
"vendor": "example",
"version": {
"code": 1000000,
"name": "1.0.0"
}
},
"deviceConfig": {},
"module": {
"package": "com.example.myapplication",
"name": ".entry",
"mainAbility": ".MainAbility",
"deviceType": [
"default",
"tablet"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"formsEnabled": false,
"name": ".MainAbility",
"srcLanguage": "ets",
"srcPath": "MainAbility",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"label": "$string:MainAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
\ No newline at end of file
# 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("//build/config/ohos/config.gni")
import("//build/ohos.gni")
import("//foundation/arkui/napi/napi.gni")
AVCODEC_ROOT_DIR = "//foundation/multimedia/av_codec/"
config("config") {
visibility = [ ":*" ]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Wunused-variable",
]
}
ohos_shared_library("entry") {
sources = [ "./hello.cpp" ]
if (!(product_name == "m40")) {
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",
"$AVCODEC_ROOT_DIR/interfaces/kits/c/",
]
configs = [ ":config" ]
deps = [
"$AVCODEC_ROOT_DIR/interfaces/kits/c:native_media_adec",
"$AVCODEC_ROOT_DIR/interfaces/kits/c:native_media_aenc",
"$AVCODEC_ROOT_DIR/interfaces/kits/c:native_media_avdemuxer",
"$AVCODEC_ROOT_DIR/interfaces/kits/c:native_media_avmuxer",
"$AVCODEC_ROOT_DIR/interfaces/kits/c:native_media_avsource",
"$AVCODEC_ROOT_DIR/interfaces/kits/c:native_media_codecbase",
"$AVCODEC_ROOT_DIR/interfaces/kits/c:native_media_core",
"$AVCODEC_ROOT_DIR/interfaces/kits/c:native_media_vdec",
"$AVCODEC_ROOT_DIR/interfaces/kits/c:native_media_venc",
]
output_extension = "so"
part_name = "av_codec"
subsystem_name = "multimedia"
}
#include "napi/native_api.h"
#include "native_avcodec_audiodecoder.h"
#include "native_avcodec_audioencoder.h"
#include "native_avcodec_videodecoder.h"
#include "native_avcodec_videoencoder.h"
#include "native_avcodec_base.h"
#include "native_avmemory.h"
#include "native_avmuxer.h"
static napi_value Demuxer(napi_env env, napi_callback_info info)
{
OH_AVSource_CreateWithURI(nullptr);
OH_AVSource_CreateWithFD(-1, 0, 0);
OH_AVSource_Destroy(nullptr);
OH_AVSource_GetSourceFormat(nullptr);
OH_AVSource_GetTrackFormat(nullptr, -1);
OH_AVDemuxer_CreateWithSource(nullptr);
OH_AVDemuxer_Destroy(nullptr);
OH_AVDemuxer_SelectTrackByID(nullptr, -1);
OH_AVDemuxer_UnselectTrackByID(nullptr, -1);
OH_AVDemuxer_ReadSample(nullptr, 0, nullptr, nullptr);
OH_AVErrCode result = OH_AVDemuxer_SeekToTime(nullptr, 0, 0);
napi_value res;
napi_create_int32(env, result, &res);
return res;
}
static napi_value CreateAudioCapture(napi_env env, napi_callback_info info)
{
const char *mime = "video/avc";
OH_AVCodec *avCode = OH_VideoDecoder_CreateByMime(mime);
OH_AVErrCode result = OH_VideoDecoder_Prepare(avCode);
OH_VideoDecoder_Destroy(avCode);
napi_value res;
napi_create_int32(env, result, &res);
return res;
}
static napi_value Capability(napi_env env, napi_callback_info info)
{
OH_AVCodec_GetCapability(nullptr, true);
OH_AVCodec_GetCapabilityByCategory("", true, HARDWARE);
OH_AVCapability_IsHardware(nullptr);
OH_AVCapability_GetName(nullptr);
OH_AVCapability_GetMaxSupportedInstances(nullptr);
OH_AVCapability_GetEncoderBitrateRange(nullptr, nullptr);
OH_AVCapability_IsEncoderBitrateModeSupported(nullptr, BITRATE_MODE_CBR);
OH_AVCapability_GetEncoderQualityRange(nullptr, nullptr);
OH_AVCapability_GetEncoderComplexityRange(nullptr, nullptr);
const int32_t *sampleRates = nullptr;
OH_AVCapability_GetAudioSupportedSampleRates(nullptr, &sampleRates, nullptr);
OH_AVCapability_GetAudioChannelCountRange(nullptr, nullptr);
OH_AVCapability_GetVideoWidthAlignment(nullptr, nullptr);
OH_AVCapability_GetVideoHeightAlignment(nullptr, nullptr);
OH_AVCapability_GetVideoWidthRangeForHeight(nullptr, 0, nullptr);
OH_AVCapability_GetVideoHeightRangeForWidth(nullptr, 0, nullptr);
OH_AVCapability_GetVideoWidthRange(nullptr, nullptr);
OH_AVCapability_GetVideoHeightRange(nullptr, nullptr);
OH_AVCapability_IsVideoSizeSupported(nullptr, 0, 0);
OH_AVCapability_GetVideoFrameRateRange(nullptr, nullptr);
OH_AVCapability_GetVideoFrameRateRangeForSize(nullptr, 0, 0, nullptr);
OH_AVCapability_AreVideoSizeAndFrameRateSupported(nullptr, 0, 0, 0);
const int32_t *temp = nullptr;
OH_AVCapability_GetVideoSupportedPixelFormats(nullptr, &temp, nullptr);
OH_AVCapability_GetSupportedProfiles(nullptr, &temp, nullptr);
OH_AVErrCode result = OH_AVCapability_GetSupportedLevelsForProfile(nullptr, 0, &temp, nullptr);
OH_AVCapability_AreProfileAndLevelSupported(nullptr, 0, 0);
napi_value res;
napi_create_int32(env, result, &res);
return res;
}
static napi_value VideoEncoder(napi_env env, napi_callback_info info)
{
OH_VideoEncoder_CreateByMime(nullptr);
OH_VideoEncoder_CreateByName(nullptr);
OH_VideoEncoder_Destroy(nullptr);
OH_AVCodecAsyncCallback cb;
cb.onError = NULL;
cb.onStreamChanged = NULL;
cb.onNeedInputData = NULL;
cb.onNeedOutputData = NULL;
OH_VideoEncoder_SetCallback(nullptr, cb, nullptr);
OH_VideoEncoder_Configure(nullptr, nullptr);
OH_VideoEncoder_Prepare(nullptr);
OH_VideoEncoder_Start(nullptr);
OH_VideoEncoder_Stop(nullptr);
OH_VideoEncoder_Flush(nullptr);
OH_VideoEncoder_Reset(nullptr);
OH_VideoEncoder_GetOutputDescription(nullptr);
OH_VideoEncoder_SetParameter(nullptr, nullptr);
OHNativeWindow *window = nullptr;
OH_VideoEncoder_GetSurface(nullptr, &window);
OH_VideoEncoder_FreeOutputData(nullptr, 0);
OH_VideoEncoder_NotifyEndOfStream(nullptr);
OH_AVCodecBufferAttr attr;
attr.pts = 0;
attr.size = 0;
attr.offset = 0;
attr.flags = AVCODEC_BUFFER_FLAGS_EOS;
OH_VideoEncoder_PushInputData(nullptr, 0, attr);
OH_VideoEncoder_GetInputDescription(nullptr);
OH_AVErrCode result = OH_VideoEncoder_IsValid(nullptr, nullptr);
napi_value res;
napi_create_int32(env, result, &res);
return res;
}
static napi_value VideoDecoder(napi_env env, napi_callback_info info)
{
OH_VideoDecoder_CreateByMime(nullptr);
OH_VideoDecoder_CreateByName(nullptr);
OH_VideoDecoder_Destroy(nullptr);
OH_AVCodecAsyncCallback cb;
cb.onError = NULL;
cb.onStreamChanged = NULL;
cb.onNeedInputData = NULL;
cb.onNeedOutputData = NULL;
OH_VideoDecoder_SetCallback(nullptr, cb, nullptr);
OH_VideoDecoder_SetSurface(nullptr, nullptr);
OH_VideoDecoder_Configure(nullptr, nullptr);
OH_VideoDecoder_Prepare(nullptr);
OH_VideoDecoder_Start(nullptr);
OH_VideoDecoder_Stop(nullptr);
OH_VideoDecoder_Flush(nullptr);
OH_VideoDecoder_Reset(nullptr);
OH_VideoDecoder_GetOutputDescription(nullptr);
OH_VideoDecoder_SetParameter(nullptr, nullptr);
OH_AVCodecBufferAttr attr;
attr.pts = 0;
attr.size = 0;
attr.offset = 0;
attr.flags = AVCODEC_BUFFER_FLAGS_NONE;
OH_VideoDecoder_PushInputData(nullptr, 0, attr);
OH_VideoDecoder_RenderOutputData(nullptr, 0);
OH_VideoDecoder_FreeOutputData(nullptr, 0);
OH_AVErrCode result = OH_VideoDecoder_IsValid(nullptr, nullptr);
napi_value res;
napi_create_int32(env, result, &res);
return res;
}
// audio decode
static napi_value AudioDecodeTest(napi_env env, napi_callback_info info)
{
OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime("aaa");
audioDec = OH_AudioDecoder_CreateByName("aaa");
OH_AVErrCode ret = AV_ERR_OK;
OH_AudioDecoder_Destroy(audioDec);
struct OH_AVCodecAsyncCallback callback = {nullptr, nullptr, nullptr, nullptr};
OH_AudioDecoder_SetCallback(audioDec, callback, nullptr);
OH_AVFormat *format = nullptr;
OH_AudioDecoder_Configure(audioDec, format);
OH_AudioDecoder_Prepare(audioDec);
OH_AudioDecoder_Start(audioDec);
OH_AudioDecoder_Stop(audioDec);
OH_AudioDecoder_Flush(audioDec);
OH_AudioDecoder_Reset(audioDec);
OH_AudioDecoder_GetOutputDescription(audioDec);
OH_AudioDecoder_SetParameter(audioDec, format);
OH_AVCodecBufferAttr attr;
uint32_t index = 0;
OH_AudioDecoder_PushInputData(audioDec, index, attr);
OH_AudioDecoder_FreeOutputData(audioDec, index);
bool isVaild;
OH_AudioDecoder_IsValid(audioDec, &isVaild);
napi_value res;
napi_create_int32(env, ret, &res);
return res;
}
// audio encode
static napi_value AudioEncodeTest(napi_env env, napi_callback_info info)
{
OH_AVCodec *audioEnc = OH_AudioEncoder_CreateByMime("aaa");
audioEnc = OH_AudioEncoder_CreateByName("aaa");
OH_AVErrCode ret = AV_ERR_OK;
OH_AudioEncoder_Destroy(audioEnc);
struct OH_AVCodecAsyncCallback callback = {nullptr, nullptr, nullptr, nullptr};
OH_AudioEncoder_SetCallback(audioEnc, callback, nullptr);
OH_AVFormat *format = nullptr;
OH_AudioEncoder_Configure(audioEnc, format);
OH_AudioEncoder_Prepare(audioEnc);
OH_AudioEncoder_Start(audioEnc);
OH_AudioEncoder_Stop(audioEnc);
OH_AudioEncoder_Flush(audioEnc);
OH_AudioEncoder_Reset(audioEnc);
OH_AudioEncoder_GetOutputDescription(audioEnc);
OH_AudioEncoder_SetParameter(audioEnc, format);
OH_AVCodecBufferAttr attr;
uint32_t index = 0;
OH_AudioEncoder_PushInputData(audioEnc, index, attr);
OH_AudioEncoder_FreeOutputData(audioEnc, index);
bool isVaild;
OH_AudioEncoder_IsValid(audioEnc, &isVaild);
napi_value res;
napi_create_int32(env, ret, &res);
return res;
}
// avmuxer
static napi_value AVMuxerTest(napi_env env, napi_callback_info info)
{
OH_AVOutputFormat format = AV_OUTPUT_FORMAT_M4A;
int32_t fd = -1;
OH_AVErrCode ret = AV_ERR_OK;
OH_AVMuxer *avmuxer = OH_AVMuxer_Create(fd, format);
int32_t rotation = 90;
OH_AVMuxer_SetRotation(avmuxer, rotation);
int32_t trackId;
OH_AVFormat *trackFormat = nullptr;
OH_AVMuxer_AddTrack(avmuxer, &trackId, trackFormat);
OH_AVMuxer_Start(avmuxer);
OH_AVMemory *sampleBuffer = nullptr;
OH_AVCodecBufferAttr info1;
OH_AVMuxer_WriteSample(avmuxer, trackId, sampleBuffer, info1);
OH_AVMuxer_Stop(avmuxer);
OH_AVMuxer_Destroy(avmuxer);
napi_value res;
napi_create_int32(env, ret, &res);
return res;
}
// avmemory
static napi_value AVMemoryTest(napi_env env, napi_callback_info info)
{
OH_AVMemory *avMemBuffer = OH_AVMemory_Create(100);
OH_AVMemory_GetAddr(avMemBuffer);
int32_t ret = AV_ERR_OK;
OH_AVMemory_GetSize(avMemBuffer);
OH_AVMemory_Destroy(avMemBuffer);
napi_value res;
napi_create_int32(env, ret, &res);
return res;
}
EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
{"demuxer", nullptr, Demuxer, nullptr, nullptr, nullptr, napi_default, nullptr},
{"capability", nullptr, Capability, nullptr, nullptr, nullptr, napi_default, nullptr},
{"videoEncoder", nullptr, VideoEncoder, nullptr, nullptr, nullptr, napi_default, nullptr},
{"videoDecoder", nullptr, VideoDecoder, nullptr, nullptr, nullptr, napi_default, nullptr},
{"createAudioCapture", nullptr, CreateAudioCapture, nullptr, nullptr, nullptr, napi_default, nullptr},
{"AudioDecodeTest", nullptr, AudioDecodeTest, nullptr, nullptr, nullptr, napi_default, nullptr},
{"AudioEncodeTest", nullptr, AudioEncodeTest, nullptr, nullptr, nullptr, napi_default, nullptr},
{"AVMuxerTest", nullptr, AVMuxerTest, nullptr, nullptr, nullptr, napi_default, nullptr},
{"AVMemoryTest", nullptr, AVMemoryTest, nullptr, nullptr, nullptr, napi_default, nullptr},
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
return exports;
}
EXTERN_C_END
static napi_module demoModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
// 模块对外接口注册函数
.nm_register_func = Init,
// 自定义模块
.nm_modname = "entry",
.nm_priv = ((void *)0),
.reserved = {0},
};
extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
{
napi_module_register(&demoModule);
}
export const demuxer: () => number;
export const capability: () => number;
export const videoEncoder: () => number;
export const videoDecoder: () => number;
{
"name": "libentry.so",
"types": "./index.d.ts",
"version": "",
"description": "Please describe the basic information."
}
\ No newline at end of file
import hilog from '@ohos.hilog';
export default {
onCreate() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Application onCreate');
},
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Application onDestroy');
},
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import testNapi from 'libentry.so'
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3));
})
}
.width('100%')
}
.height('100%')
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.myapplication",
"vendor": "example",
"version": {
"code": 1000000,
"name": "1.0.0"
}
},
"deviceConfig": {},
"module": {
"package": "com.example.myapplication_test",
"name": ".entry_test",
"mainAbility": ".TestAbility",
"deviceType": [
"default",
"tablet"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry_test",
"moduleType": "feature",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"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": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
export default {
onCreate() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Application onCreate');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Application onDestroy');
},
}
\ No newline at end of file
import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s',
JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare');
}
onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s',
JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s',
d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s',
d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
};
\ No newline at end of file
import hilog from '@ohos.hilog';
import entry_add from 'libentry.so';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
export default function abilityTest() {
describe('ActsAbilityTest', function () {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () {
// 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(function () {
// 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(function () {
// 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(function () {
// 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, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin1');
console.info("add-------------c:--");
let c1 = entry_add.createAudioCapture()
console.info("add-------------c:--"+c1);
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(true).assertTrue();
})
})
}
\ No newline at end of file
import abilityTest from './Ability.test'
export default function testsuite() {
abilityTest()
}
\ No newline at end of file
{
"string": [
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
{
"hvigorVersion": "2.4.2",
"dependencies": {
"@ohos/hvigor-ohos-plugin": "2.4.2"
}
}
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
export { legacyAppTasks } from '@ohos/hvigor-ohos-plugin';
\ No newline at end of file
#!/bin/bash
# ----------------------------------------------------------------------------
# Hvigor startup script, version 1.0.0
#
# Required ENV vars:
# ------------------
# NODE_HOME - location of a Node home dir
# or
# Add /usr/local/nodejs/bin to the PATH environment variable
# ----------------------------------------------------------------------------
HVIGOR_APP_HOME=$(dirname $(readlink -f $0))
HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
warn() {
echo ""
echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
error() {
echo ""
echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
fail() {
error "$@"
exit 1
}
# Determine node to start hvigor wrapper script
if [ -n "${NODE_HOME}" ];then
EXECUTABLE_NODE="${NODE_HOME}/bin/node"
if [ ! -x "$EXECUTABLE_NODE" ];then
fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed"
fi
else
EXECUTABLE_NODE="node"
which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
fi
# Check hvigor wrapper script
if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
fi
# start hvigor-wrapper script
exec "${EXECUTABLE_NODE}" \
"${HVIGOR_WRAPPER_SCRIPT}" "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Hvigor startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js
set NODE_EXE=node.exe
goto start
:start
@rem Find node.exe
if defined NODE_HOME goto findNodeFromNodeHome
%NODE_EXE% --version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:findNodeFromNodeHome
set NODE_HOME=%NODE_HOME:"=%
set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE%
if exist "%NODE_EXE_PATH%" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:execute
@rem Execute hvigor
"%NODE_EXE%" %WRAPPER_MODULE_PATH% %*
if "%ERRORLEVEL%" == "0" goto hvigorwEnd
:fail
exit /b 1
:hvigorwEnd
if "%OS%" == "Windows_NT" endlocal
:end
{
"lockfileVersion": 1,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {
"@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6"
},
"packages": {
"@ohos/hypium@1.0.6": {
"resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz",
"integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ=="
}
}
}
\ No newline at end of file
{
"license": "",
"devDependencies": {
"@ohos/hypium": "1.0.6"
},
"author": "",
"name": "myapplication",
"description": "Please describe the basic information.",
"main": "",
"version": "1.0.0",
"dependencies": {}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册