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

!8072 avRecorder多场景用例 avPlayer增加api覆盖

Merge pull request !8072 from Nicklaus/master
......@@ -638,7 +638,7 @@ export async function seekLoopWithoutCallback(src, avPlayer, done) {
console.info(`case Initialized in, surfaceID is ${surfaceID}`);
avPlayer = await idle(src, avPlayer)
await setSource(avPlayer, src);
if(avPlayer.state == AV_PLAYER_STATE.INITIALIZED) {
if(avPlayer.state == 'initialized') {
avPlayer.surfaceId = surfaceID;
preparePromise(avPlayer);
await sleep(2000);
......@@ -679,7 +679,7 @@ export async function prepareToStopLoop(src, avPlayer, done) {
// prepare to stop loop 1000 times
for(var i = 0;i < 1000; i++){
await avPlayer.prepare().then(() => {
expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
expect(avPlayer.state).assertEqual('prepared');
console.info('prepareToStopLoop avPlayer state is prepared')
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
......@@ -717,13 +717,13 @@ export async function prepareToResetLoop(src, avPlayer, done) {
await avPlayer.play().then(() => {
console.info('prepareToResetLoop play success');
expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
expect(avPlayer.state).assertEqual('playing');
}, (err) => {
console.error('prepareToResetLoop play filed,error message is :' + err.message)
})
await avPlayer.reset().then(() => {
expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
expect(avPlayer.state).assertEqual('idle');
console.info('prepareToResetLoop avPlayer state is reset')
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
......@@ -1029,7 +1029,7 @@ export function playTimeCallback(avPlayer, done) {
break;
case AV_PLAYER_STATE.PAUSED:
console.info('playTimeWithCallback play state is PAUSED')
expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
expect(avPlayer.state).assertEqual('paused');
start = Date.now();
console.info(`playTimeCallback start time is : ${start}`)
// step 3: pause -> playing loop
......@@ -2118,12 +2118,12 @@ function setAVPlayerPlay(src, avPlayer, done) {
break;
case AV_PLAYER_STATE.COMPLETED:
expect(avPlayer.currentTime).assertEqual(avPlayer.duration);
expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.COMPLETED);
expect(avPlayer.state).assertEqual('completed');
avPlayer.release().then(() => {
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
break;
case AV_PLAYER_STATE.RELEASED:
expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
expect(avPlayer.state).assertEqual('released');
offCallback(avPlayer, ['stateChange', 'error']);
avPlayer = null;
done();
......
/**
* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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 media from '@ohos.multimedia.media'
import * as mediaTestBase from './MediaTestBase.js';
export async function idle(avRecorder) {
console.info('case createAVRecorder called');
await media.createAVRecorder().then((recorder) => {
if (recorder != null) {
avRecorder = recorder;
console.info('createAVRecorder success');
} else {
console.info('createAVRecorder fail');
}
}).catch((error) => {
console.info(`createAVRecorder catchCallback, error:${error}`);
});
return avRecorder;
}
export const AV_RECORDER_STATE = {
IDLE : 'idle',
PREPARED : 'prepared',
STARTED : 'started',
PAUSED : 'paused',
STOPPED : 'stopped',
RELEASED : 'released',
ERROR : 'error',
}
export function prepareCallback(avRecorder, avConfig) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.prepare(avConfig, (err) => {
console.info('case prepare called' + err);
if (err == null) {
console.info('prepare success');
} else {
console.error(`case prepare error, errMessage is ${err.message}`);
}
})
}
export function preparePromise(avRecorder, avConfig) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.prepare(avConfig).then(() => {
console.info('prepare success');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
export function getInputSurfacePromise(avRecorder) {
let surfaceID = null;
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.getInputSurface().then((surfaceId) => {
console.info('getInputSurface success');
surfaceID = surfaceId;
}).catch((err) => {
console.info('getInputSurface failed and catch error is ' + err.message);
});
// videoOutput = await cameraManager.createVideoOutput(videoProfiles[0], surfaceID);
}
export function getInputSurfaceCallback(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
let surfaceID = null;
avRecorder.getInputSurface((err, surfaceId) => {
if (err == null) {
console.info('getInputSurface success');
surfaceID = surfaceId;
} else {
console.info('getInputSurface failed and error is ' + err.message);
}
});
// videoOutput = await cameraManager.createVideoOutput(videoProfiles[0], surfaceID);
}
export function startCallback(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.start((err) => {
console.info('case start called');
if (err == null) {
console.info('start AVRecorder success');
} else {
console.info('start AVRecorder failed and error is ' + err.message);
}
})
}
export function startPromise(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.start().then(() => {
console.info('start success');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
export function pauseCallback(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.pause((err) => {
console.info('case pause called');
if (err == null) {
console.info('pause AVRecorder success');
} else {
console.info('pause AVRecorder failed and error is ' + err.message);
}
})
}
export function pausePromise(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.pause().then(() => {
console.info('pause success');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
export function resumeCallback(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.resume((err) => {
console.info('case resume called');
if (err == null) {
console.info('resume AVRecorder success');
} else {
console.info('resume AVRecorder failed and error is ' + err.message);
}
})
}
export function resumePromise(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.resume().then(() => {
console.info('resume success');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
export function stopCallback(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.stop((err) => {
console.info('case stop called');
if (err == null) {
console.info('stop AVRecorder success');
} else {
console.info('stop AVRecorder failed and error is ' + err.message);
}
})
}
export function stopPromise(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.stop().then(() => {
console.info('stop success');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
export function resetCallback(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.reset((err) => {
console.info('case reset called');
if (err == null) {
console.info('reset AVRecorder success');
} else {
console.info('reset AVRecorder failed and error is ' + err.message);
}
})
}
export function resetPromise(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.reset().then(() => {
console.info('reset success');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
export function releaseCallback(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.release((err) => {
console.info('case release called');
if (err == null) {
console.info('release AVRecorder success');
} else {
console.info('release AVRecorder failed and error is ' + err.message);
}
})
}
export function releasePromise(avRecorder) {
if (typeof(avRecorder) == 'undefined') {
return;
}
avRecorder.release().then(() => {
console.info('release success');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
export function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export function offCallback(avRecorder, typeArr)
{
if (avRecorder == null) {
return;
}
for (let i = 0; i < typeArr.length; i++) {
switch (typeArr[i]) {
case 'stateChange':
avRecorder.off('stateChange');
break;
case 'error':
avRecorder.off('error');
break;
default:
break;
}
}
}
export async function setOnCallback(avConfig, avRecorder, recorderTime, done) {
console.info(`case setOnCallback in`);
avRecorder.on('stateChange', async (state, reason) => {
console.info('case state has changed, new state is :' + state);
switch (state) {
case AV_RECORDER_STATE.IDLE:
console.info(`case avRecorderWithCallBack is idle`);
expect(avRecorder.state).assertEqual("idle");
//start->stop->release
prepareCallback(avRecorder, avConfig);
break;
case AV_RECORDER_STATE.PREPARED:
console.info(`case avRecorderWithCallBack is prepared`);
expect(avRecorder.state).assertEqual('prepared');
startCallback(avRecorder);
break;
case AV_RECORDER_STATE.STARTED:
console.info(`case avRecorderWithCallBack is started`)
expect(avRecorder.state).assertEqual('started');
await sleep(recorderTime);
stopCallback(avRecorder);
break;
case AV_RECORDER_STATE.PAUSED:
console.info(`case avRecorderWithCallBackis paused`)
expect(avRecorder.state).assertEqual('paused');
break;
case AV_RECORDER_STATE.STOPPED:
console.info(`case avRecorderWithCallBack is stopped`)
expect(avRecorder.state).assertEqual('stopped');
avRecorder.release()
break;
case AV_RECORDER_STATE.RELEASED:
console.info(`case avRecorderWithCallBack is released`);
expect(avRecorder.state).assertEqual('released');
done();
break;
case AV_RECORDER_STATE.ERROR:
console.info(`case avRecorderWithCallBack is error`)
expect(avRecorder.state).assertEqual('error');
break;
default:
console.info('case state is unknown');
}
});
avRecorder.on('error', (err) => {
console.info('case avRecorder.on(error) called, errMessage is ' + err.message);
});
}
export async function setPrepareOnCallback(avConfig, avRecorder, recorderTime, done) {
console.info(`case setOnCallback in`);
avRecorder.on('stateChange', async (state, reason) => {
console.info('case state has changed, new state is :' + state);
switch (state) {
case AV_RECORDER_STATE.PREPARED:
console.info(`case AV_RECORDER_STATE.PREPARED`);
expect(avRecorder.state).assertEqual('prepared');
releaseCallback(avRecorder);
break;
case AV_RECORDER_STATE.RELEASED:
console.info(`case avRecorderReliabilitTest03 is released`);
expect(avRecorder.state).assertEqual('released');
done();
break;
case AV_RECORDER_STATE.ERROR:
console.info(`case AV_RECORDER_STATE.ERROR`)
expect(avRecorder.state).assertEqual('error');
break;
default:
console.info('case state is unknown');
}
});
}
export async function avRecorderWithCallBack(avConfig, avRecorder, recorderTime, done) {
avRecorder = await idle(avRecorder)
setOnCallback(avConfig, avRecorder, recorderTime, done);
await avRecorder.prepare(avConfig)
}
export async function avRecorderReliabilitTest01(avConfig, avRecorder, recorderTime, done) {
let result = true;
avRecorder = await idle(avRecorder);
console.info('case avConfig.url is ' + avConfig.url);
await avRecorder.pause().then(() => {
console.info('pause AVRecorder success');
}).catch((err) => {
console.info('pause AVRecorder failed and catch error is ' + err.message);
result = false
});
expect(result).assertEqual(false);
await avRecorder.prepare(avConfig).then(() => {
expect(avRecorder.state).assertEqual(AV_RECORDER_STATE.PREPARED);
console.info('prepare success');
}).catch((err) => {
console.info('prepare failed and catch error is ' + err.message);
});
await avRecorder.release().then(() => {
console.info('release AVRecorder success');
expect(avRecorder.state).assertEqual(AV_RECORDER_STATE.RELEASED);
done();
}).catch((err) => {
console.info('release AVRecorder failed and catch error is ' + err.message);
});
}
export async function avRecorderReliabilitTest02(avConfig, avRecorder, recorderTime, done) {
avRecorder = await idle(avRecorder);
await avRecorder.prepare(avConfig).then(() => {
expect(avRecorder.state).assertEqual(AV_RECORDER_STATE.PREPARED);
console.info('avRecorderReliabilitTest02 prepare success');
}).catch((err) => {
console.info('avRecorderReliabilitTest02 prepare failed and catch error is ' + err.message);
});
await avRecorder.release().then(() => {
console.info('avRecorderReliabilitTest02 release AVRecorder success');
expect(avRecorder.state).assertEqual(AV_RECORDER_STATE.RELEASED);
done();
}).catch((err) => {
console.info('avRecorderReliabilitTest02 release AVRecorder failed and catch error is ' + err.message);
});
}
export async function avRecorderReliabilitTest03(avConfig, avRecorder, recorderTime, done) {
avRecorder = await idle(avRecorder);
setPrepareOnCallback(avConfig, avRecorder, recorderTime, done)
await avRecorder.prepare(avConfig)
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
/**
* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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
* 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,
......@@ -12,506 +12,147 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import media from '@ohos.multimedia.media'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import media from '@ohos.multimedia.media';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import * as avRecorderTestBase from '../../../../../AVRecorderTestBase.js';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function avRecorderTest() {
describe('avRecorderTest', function () {
let avRecorder = null;
const AV_SOURCES = [
'audio_1.m4a',
'audio_2.m4a',
'audio_3.m4a',
'audio_4.m4a',
'audio_5.m4a',
'audio_6.m4a',
'audio_7.m4a',
'audio_8.m4a',
'audio_9.m4a',
'audio_10.m4a',
'audio_11.m4a',
'audio_12.m4a'
]
export default function AVRecorderFuncTest(recorderContxt) {
describe('AVRecorderFuncTest', function () {
const RECORDER_TIME = 3000;
const PAUSE_TIME = 1000;
const END = 0;
const CREATE_PROMISE = 1;
const CREATE_CALLBACK = 2;
const PREPARE_PROMISE = 3;
const PREPARE_CALLBACK = 4;
const GETSURFACE_PROMISE = 5;
const GETSURFACE_CALLBACK = 6;
const STARTCAMERA = 7;
const START_PROMISE = 8;
const START_CALLBACK = 9;
const PAUSE_PROMISE = 10;
const PAUSE_CALLBACK = 11;
const RESUME_PROMISE = 12;
const RESUME_CALLBACK = 13;
const STOP_PROMISE = 14;
const STOP_CALLBACK = 15;
const RESET_PROMISE = 16;
const RESET_CALLBACK = 17;
const RELEASE_PROMISE = 18;
const RELEASE_CALLBACK = 19;
const SETCALLBACKOFF = 20;
const STOPVIDEOOUTPUT = 21;
let mySteps = new Array();
let caseCount = 0;
let fdPath;
const FORMAT_M4A = media.ContainerFormatType.CFT_MPEG_4A;
const ENCORDER_AAC = media.CodecMimeType.AUDIO_AAC;
const ONLYAUDIO_TYPE = 'only_audio';
let trackArray;
let fdObject;
let playerSurfaceId = '';
let avRecorder = null;
let surfaceID = '';
let needDone = false;
let fdPath;
let TAG = "[AudioRecorderLocalTest] ";
let avProfile = {
audioBitrate : 48000,
audioChannels : 2,
audioCodec : media.CodecMimeType.AUDIO_AAC,
audioSampleRate : 48000,
fileFormat : media.ContainerFormatType.CFT_MPEG_4,
videoBitrate : 48000,
videoCodec : media.CodecMimeType.VIDEO_MPEG4,
videoFrameWidth : 640,
videoFrameHeight : 480,
videoFrameRate : 30
audioCodec : ENCORDER_AAC,
fileFormat : FORMAT_M4A,
}
let avConfig = {
audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC,
videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV,
profile : avProfile,
url : 'fd://',
rotation : 0,
location : { latitude : 30, longitude : 130 }
}
let audioProfile = {
audioBitrate : 48000,
audioChannels : 2,
audioCodec : media.CodecMimeType.AUDIO_AAC,
audioSampleRate : 48000,
fileFormat : media.ContainerFormatType.CFT_MPEG_4,
}
let audioConfig = {
audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC,
profile : audioProfile,
url : 'fd://',
rotation : 0,
location : { latitude : 30, longitude : 130 }
}
beforeAll(async function () {
console.info('beforeAll case In');
console.info('beforeAll in1');
let permissionName1 = 'ohos.permission.MICROPHONE';
let permissionName2 = 'ohos.permission.MEDIA_LOCATION';
let permissionName3 = 'ohos.permission.READ_MEDIA';
let permissionName4 = 'ohos.permission.WRITE_MEDIA';
let permissionName5 = 'ohos.permission.CAMERA';
let permissionNames = [permissionName1, permissionName2, permissionName3, permissionName4, permissionName5];
let permissionNames = [permissionName1, permissionName2, permissionName3, permissionName4];
await mediaTestBase.getPermission(permissionNames);
await mediaTestBase.msleepAsync(2000);
await mediaTestBase.driveFn(3);
console.info('beforeAll case Out');
await mediaTestBase.msleepAsync(5000);
console.info('beforeAll out');
})
beforeEach(async function () {
console.info('beforeEach case In');
playerSurfaceId = globalThis.value;
avRecorder = undefined;
surfaceID = '';
caseCount += 1;
needDone = false;
console.info('beforeEach case Out');
beforeEach(function () {
console.info('beforeEach case');
})
afterEach(async function () {
console.info('afterEach case In');
mySteps = new Array();
await releaseByPromise();
await mediaTestBase.closeFd(fdObject.fileAsset, fdObject.fdNumber);
console.info('afterEach case Out');
console.info('afterEach case');
})
afterAll(function () {
mediaTestBase.closeFd(fdObject.fileAsset, fdObject.fdNumber);
console.info('afterAll case');
})
async function getRecorderFileFd(fileName, fileType) {
console.info("case current fileName is: " + fileName);
fdObject = await mediaTestBase.getAvRecorderFd(fileName, fileType);
fdPath = "fd://" + fdObject.fdNumber.toString();
console.info("case fdPath is: " + fdPath);
/* *
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_AUDIO_FUNCTION_0100
* @tc.name : 001.test pause
* @tc.desc : Local Video 001.pause
* @tc.size : MediumTest
* @tc.type : Function test
* @tc.level : Level2
*/
it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_AUDIO_FUNCTION_0100', 0, async function (done) {
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_AUDIO_FUNCTION_0100 start')
fdObject = await mediaTestBase.getAvRecorderFd(AV_SOURCES[0], "audio");
fdPath = "fd://" + fdObject.fdNumber;
avConfig.url = fdPath;
console.info("case to out getRecorderFileFd");
}
async function createAVRecorderByPromise(done) {
console.info(`case to create avRecorder by promise`);
await media.createAVRecorder().then((recorder) => {
console.info('case createAVRecorder promise called');
if (typeof (recorder) != 'undefined') {
avRecorder = recorder;
expect(avRecorder.state).assertEqual('idle');
setCallbackOn(done);
nextStep(done);
} else {
console.info('case create avRecorder failed!!!');
expect().assertFail();
done();
}
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
function createAVRecorderByCallback(done) {
console.info(`case to create avRecorder by callback`);
media.createAVRecorder((err, recorder) => {
if (typeof (err) == 'undefined') {
console.info('case createAVRecorder callback success ');
avRecorder = recorder;
expect(avRecorder.state).assertEqual('idle');
setCallbackOn(done);
nextStep(done);
} else {
mediaTestBase.failureCallback(err);
}
});
}
async function prepareByPromise() {
console.info(`case to prepare by promise`);
await avRecorder.prepare(avConfig).then(() => {
console.info('case recorder prepare by promise called');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
function prepareByCallback() {
console.info(`case to prepare by callback`);
avRecorder.prepare(avConfig, (err) => {
if (typeof (err) == 'undefined') {
console.info('case recorder prepare by callback called');
} else {
mediaTestBase.failureCallback(err);
}
});
}
async function getInputSurfaceByPromise(done) {
console.info(`case to getsurface by promise`);
await avRecorder.getInputSurface().then((outputSurface) => {
console.info('case getInputSurface by promise called');
surfaceID = outputSurface;
console.info('case outputSurface surfaceID is: ' + surfaceID);
nextStep(done);
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
function getInputSurfaceByCallback(done) {
console.info(`case to getsurface by callback`);
avRecorder.getInputSurface((err, outputSurface) => {
if (typeof (err) == 'undefined') {
console.info('case getInputSurface by callback called');
surfaceID = outputSurface;
console.info('case outputSurface surfaceID is: ' + surfaceID);
nextStep(done);
} else {
mediaTestBase.failureCallback(err);
}
});
}
async function startByPromise() {
console.info(`case to start by promise`);
await avRecorder.start().then(() => {
console.info('case recorder start by promise called');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
function startByCallback() {
console.info(`case to start by callback`);
avRecorder.start((err) => {
if (typeof (err) == 'undefined') {
console.info('case recorder start by callback called');
} else {
mediaTestBase.failureCallback(err);
}
});
}
async function pauseByPromise() {
console.info(`case to pause by promise`);
await avRecorder.pause().then(() => {
console.info('case recorder pause by promise called');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
function pauseByCallback() {
console.info(`case to pause by callback`);
avRecorder.pause((err) => {
if (typeof (err) == 'undefined') {
console.info('case recorder pause by callback called');
} else {
mediaTestBase.failureCallback(err);
}
});
}
async function resumeByPromise() {
console.info(`case to resume by promise`);
await avRecorder.resume().then(() => {
console.info('case recorder resume by promise called');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
function resumeByCallback() {
console.info(`case to resume by callback`);
avRecorder.resume((err) => {
if (typeof (err) == 'undefined') {
console.info('case recorder resume by callback called');
} else {
mediaTestBase.failureCallback(err);
}
});
}
async function stopByPromise() {
console.info(`case to stop by promise`);
await avRecorder.stop().then(() => {
console.info('case recorder stop by promise called');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
function stopByCallback() {
console.info(`case to stop by callback`);
avRecorder.stop((err) => {
if (typeof (err) == 'undefined') {
console.info('case recorder stop by callback called');
} else {
mediaTestBase.failureCallback(err);
}
});
}
async function resetByPromise() {
console.info(`case to reset by promise`);
await avRecorder.reset().then(() => {
console.info('case recorder reset by promise called');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
function resetByCallback() {
console.info(`case to reset by callback`);
avRecorder.reset((err) => {
if (typeof (err) == 'undefined') {
console.info('case recorder reset by callback called');
} else {
mediaTestBase.failureCallback(err);
}
});
}
async function releaseByPromise(done) {
console.info(`case to release by promise`);
if (avRecorder) {
await avRecorder.release().then(() => {
console.info('case recorder release by promise called');
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
}
if(needDone) {
avRecorder = undefined;
done();
}
}
async function releaseByCallback(done) {
console.info(`case to release by callback`);
if (avRecorder) {
avRecorder.release(async(err) => {
if (typeof (err) == 'undefined') {
console.info('case recorder release by callback called');
avRecorder = undefined;
} else {
mediaTestBase.failureCallback(err);
}
});
}
if (needDone) {
avRecorder = undefined;
done();
}
}
async function nextStep(done) {
console.info("case myStep[0]: " + mySteps[0]);
if (mySteps[0] == END) {
console.info("case to END");
done();
}
switch (mySteps[0]) {
case CREATE_PROMISE:
mySteps.shift();
await createAVRecorderByPromise(done);
break;
case CREATE_CALLBACK:
mySteps.shift();
createAVRecorderByCallback(done);
break;
case PREPARE_PROMISE:
mySteps.shift();
await prepareByPromise();
break;
case PREPARE_CALLBACK:
mySteps.shift();
prepareByCallback();
break;
case GETSURFACE_PROMISE:
mySteps.shift();
await getInputSurfaceByPromise(done);
break;
case GETSURFACE_CALLBACK:
mySteps.shift();
getInputSurfaceByCallback(done);
break;
case STARTCAMERA:
mySteps.shift();
await startVideoOutput();
nextStep(done);
break;
case START_PROMISE:
mySteps.shift();
await startByPromise();
break;
case START_CALLBACK:
mySteps.shift();
startByCallback();
break;
case PAUSE_PROMISE:
mySteps.shift();
await pauseByPromise();
break;
case PAUSE_CALLBACK:
mySteps.shift();
pauseByCallback();
break;
case RESUME_PROMISE:
mySteps.shift();
await resumeByPromise();
break;
case RESUME_CALLBACK:
mySteps.shift();
resumeByCallback();
break;
case STOP_PROMISE:
mySteps.shift();
await stopByPromise();
break;
case STOP_CALLBACK:
mySteps.shift();
stopByCallback();
break;
case RESET_PROMISE:
mySteps.shift();
await resetByPromise();
break;
case RESET_CALLBACK:
mySteps.shift();
resetByCallback();
break;
case RELEASE_PROMISE:
mySteps.shift();
await releaseByPromise(done);
break;
case RELEASE_CALLBACK:
mySteps.shift();
await releaseByCallback(done);
break;
case SETCALLBACKOFF:
mySteps.shift();
setCallbackOff(done);
break;
case STOPVIDEOOUTPUT:
mySteps.shift();
await stopVideoOutput();
nextStep(done);
break;
default:
console.info('do nothing');
}
}
function setCallbackOn(done) {
console.info('case callback on');
avRecorder.on('stateChange', async (state, reason) => {
console.info('case state has changed, new state is :' + state);
switch (state) {
case 'idle':
nextStep(done);
break;
case 'prepared':
nextStep(done);
break;
case 'started':
await mediaTestBase.msleepAsync(RECORDER_TIME);
nextStep(done);
break;
case 'paused':
await mediaTestBase.msleepAsync(PAUSE_TIME);
nextStep(done);
break;
case 'stopped':
nextStep(done);
break;
case 'released':
avRecorder = undefined;
nextStep(done);
break;
case 'error':
console.info("case error state!!!");
break;
default:
console.info('case start is unknown');
nextStep(done);
}
});
avRecorder.on('error', (err) => {
console.info('case avRecorder.on(error) called, errMessage is ' + err.message);
nextStep(done);
});
}
function setCallbackOff(done) {
console.info('case callback off called');
if (avRecorder != undefined) {
console.info('case to call avRecorder.off("stateChange")');
avRecorder.off('stateChange');
console.info('case to call avRecorder.off("error")');
avRecorder.off('error');
console.info('case call avRecorder.off done');
}
needDone = true;
nextStep(done);
console.info('case callback off done');
}
avRecorderTestBase.avRecorderWithCallBack(avConfig, avRecorder, RECORDER_TIME, done);
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_AUDIO_FUNCTION_0100 end')
})
/* *
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0100
* @tc.name : 001.test pause->prepare
* @tc.desc : Local Video 01.pause->prepare
* @tc.size : MediumTest
* @tc.type : Function test
* @tc.level : Level2
*/
it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0100', 0, async function (done) {
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0100 start')
fdObject = await mediaTestBase.getAvRecorderFd(AV_SOURCES[1], "audio");
fdPath = "fd://" + fdObject.fdNumber;
avConfig.url = fdPath;
avRecorderTestBase.avRecorderReliabilitTest01(avConfig, avRecorder, RECORDER_TIME, done);
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0100 end')
})
/* *
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_FUNC_0100
* @tc.name : 01. test only avRecorder basic function by promise interfaces
* @tc.desc : test only avRecorder operation: start-pause-resume-stop
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level0
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0200
* @tc.name : 001.test prepare without callback
* @tc.desc : Local Video prepare without callback
* @tc.size : MediumTest
* @tc.type : Function test
* @tc.level : Level2
*/
it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_FUNC_0100', 0, async function (done) {
avConfig = audioConfig;
caseCount = 1;
let fileName = 'avRecorder_func_0'+ caseCount +'.m4a';
await getRecorderFileFd(fileName, 'audio');
mySteps = new Array(CREATE_PROMISE, PREPARE_PROMISE, START_PROMISE, PAUSE_PROMISE,
RESUME_PROMISE, STOP_PROMISE, RESET_PROMISE, SETCALLBACKOFF, RELEASE_PROMISE);
nextStep(done);
it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0200', 0, async function (done) {
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0200 start')
fdObject = await mediaTestBase.getAvRecorderFd(AV_SOURCES[2], "audio");
fdPath = "fd://" + fdObject.fdNumber;
avConfig.url = fdPath;
avRecorderTestBase.avRecorderReliabilitTest02(avConfig, avRecorder, RECORDER_TIME, done);
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0200 end')
})
/* *
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_FUNC_0200
* @tc.name : 01. test only avRecorder basic function by callback interfaces
* @tc.desc : test only avRecorder operation: start-pause-resume-stop
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level0
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0300
* @tc.name : 001.test prepare with callback
* @tc.desc : Local Video prepare with callback
* @tc.size : MediumTest
* @tc.type : Function test
* @tc.level : Level2
*/
it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_FUNC_0200', 0, async function (done) {
let fileName = 'avRecorder_func_0'+ caseCount +'.m4a';
await getRecorderFileFd(fileName, 'audio');
mySteps = new Array(CREATE_CALLBACK, PREPARE_CALLBACK, START_CALLBACK, PAUSE_CALLBACK,
RESUME_CALLBACK, STOP_CALLBACK, RESET_CALLBACK, SETCALLBACKOFF, RELEASE_CALLBACK);
nextStep(done);
it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0300', 0, async function (done) {
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0300 start')
fdObject = await mediaTestBase.getAvRecorderFd(AV_SOURCES[3], "audio");
fdPath = "fd://" + fdObject.fdNumber;
avConfig.url = fdPath;
avRecorderTestBase.avRecorderReliabilitTest03(avConfig, avRecorder, RECORDER_TIME, done);
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0300 end')
})
})
}
\ No newline at end of file
})
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
/**
* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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
* 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,
......@@ -12,9 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AVRecorderFuncTest from './AVRecorderFuncTest.test.js'
import avRecorderTest from './AVRecorderFuncTest.test.js'
export default function testsuite(recorderContxt) {
AVRecorderFuncTest(recorderContxt)
export default function testsuite() {
avRecorderTest()
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册