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

!8096 【媒体子系统】新增覆盖

Merge pull request !8096 from 秦莉文/OpenHarmony-3.2-Release
/**
* 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)
}
...@@ -20,7 +20,7 @@ import mediaLibrary from '@ohos.multimedia.mediaLibrary' ...@@ -20,7 +20,7 @@ import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import fileio from '@ohos.fileio' import fileio from '@ohos.fileio'
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
import { UiDriver, BY, PointerMatrix } from '@ohos.UiTest' import { UiDriver, BY, PointerMatrix } from '@ohos.UiTest'
const CODECMIMEVALUE = ['video/avc', 'audio/mp4a-latm', 'audio/mpeg'] const CODECMIMEVALUE = ['video/x-h264', 'audio/mpeg', 'video/avc', 'audio/mp4a-latm']
const context = featureAbility.getContext(); const context = featureAbility.getContext();
export async function getPermission(permissionNames) { export async function getPermission(permissionNames) {
......
...@@ -157,7 +157,7 @@ describe('PlayerLocalTestAudioFUNC', function () { ...@@ -157,7 +157,7 @@ describe('PlayerLocalTestAudioFUNC', function () {
console.info('case getTrackDescription called!!'); console.info('case getTrackDescription called!!');
if (typeof (arrayList) != 'undefined') { if (typeof (arrayList) != 'undefined') {
for (let i = 0; i < arrayList.length; i++) { for (let i = 0; i < arrayList.length; i++) {
mediaTestBase.checkDescription(arrayList[i], descriptionKey[i], descriptionValue[i]); mediaTestBase.checkOldDescription(arrayList[i], descriptionKey[i], descriptionValue[i]);
} }
} else { } else {
console.info('case getTrackDescription is failed'); console.info('case getTrackDescription is failed');
...@@ -171,7 +171,7 @@ describe('PlayerLocalTestAudioFUNC', function () { ...@@ -171,7 +171,7 @@ describe('PlayerLocalTestAudioFUNC', function () {
audioPlayer.getTrackDescription((err, arrayList) => { audioPlayer.getTrackDescription((err, arrayList) => {
if (typeof (err) == 'undefined') { if (typeof (err) == 'undefined') {
for (let i = 0; i < arrayList.length; i++) { for (let i = 0; i < arrayList.length; i++) {
mediaTestBase.checkDescription(arrayList[i], descriptionKey[i], descriptionValue[i]); mediaTestBase.checkOldDescription(arrayList[i], descriptionKey[i], descriptionValue[i]);
} }
nextStep(mySteps, done); nextStep(mySteps, done);
} else { } else {
......
...@@ -474,7 +474,7 @@ export default function AVPlayerLocalTest() { ...@@ -474,7 +474,7 @@ export default function AVPlayerLocalTest() {
it('SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_GETTRECKDESCRIPTION_0200', 0, async function (done) { it('SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_GETTRECKDESCRIPTION_0200', 0, async function (done) {
let audioTrackKey = new Array('channel_count', 'codec_mime', 'sample_rate', 'track_index', let audioTrackKey = new Array('channel_count', 'codec_mime', 'sample_rate', 'track_index',
'track_type'); 'track_type');
let audioTrackValue = new Array(1, 2, 48000, 0, 0); let audioTrackValue = new Array(1, 1, 48000, 0, 0);
let descriptionKey = new Array(audioTrackKey); let descriptionKey = new Array(audioTrackKey);
let descriptionValue = new Array(audioTrackValue); let descriptionValue = new Array(audioTrackValue);
testCheckTrackDescription(fileDescriptor2, avPlayer, descriptionKey, descriptionValue, done) testCheckTrackDescription(fileDescriptor2, avPlayer, descriptionKey, descriptionValue, done)
......
...@@ -81,7 +81,7 @@ export default function AVPlayerStabilityTest() { ...@@ -81,7 +81,7 @@ export default function AVPlayerStabilityTest() {
beforeAll(async function () { beforeAll(async function () {
console.info('beforeAll case'); console.info('beforeAll case');
for(var i = 0;i < VIDEO_SOURCES.length; i++){ for (var i = 0; i < VIDEO_SOURCES.length; i++) {
await getStageFdRead(VIDEO_SOURCES[i]).then((testNumber) => { await getStageFdRead(VIDEO_SOURCES[i]).then((testNumber) => {
fdNumber = testNumber; fdNumber = testNumber;
console.info(TAG + 'this fdNumber is :' + fdNumber) console.info(TAG + 'this fdNumber is :' + fdNumber)
...@@ -107,12 +107,12 @@ export default function AVPlayerStabilityTest() { ...@@ -107,12 +107,12 @@ export default function AVPlayerStabilityTest() {
} }
beforeEach(async function() { beforeEach(async function () {
console.info('beforeEach case'); console.info('beforeEach case');
await AVPlayerTestBase.sleep(1000); await AVPlayerTestBase.sleep(1000);
}) })
afterEach(async function() { afterEach(async function () {
if (avPlayer != null) { if (avPlayer != null) {
avPlayer.release().then(() => { avPlayer.release().then(() => {
console.info(TAG + 'this testCase execution completed') console.info(TAG + 'this testCase execution completed')
...@@ -122,9 +122,9 @@ export default function AVPlayerStabilityTest() { ...@@ -122,9 +122,9 @@ export default function AVPlayerStabilityTest() {
await AVPlayerTestBase.sleep(1000); await AVPlayerTestBase.sleep(1000);
}) })
afterAll(async function() { afterAll(async function () {
console.info('afterAll case'); console.info('afterAll case');
for(var i = 0;i < fdNumbers.length; i++){ for (var i = 0; i < fdNumbers.length; i++) {
await mediaTestBase.closeFdNumber(fdNumbers[i]); await mediaTestBase.closeFdNumber(fdNumbers[i]);
} }
}) })
...@@ -223,7 +223,7 @@ export default function AVPlayerStabilityTest() { ...@@ -223,7 +223,7 @@ export default function AVPlayerStabilityTest() {
*/ */
it('SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_MP4_0500', 0, async function (done) { it('SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_MP4_0500', 0, async function (done) {
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_MP4_0500 start') console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_MP4_0500 start')
AVPlayerTestBase.avPlayerPlay(videos[4], avPlayer,done); AVPlayerTestBase.avPlayerPlay(videos[4], avPlayer, done);
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_MP4_0500 end') console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_MP4_0500 end')
}) })
...@@ -761,19 +761,7 @@ export default function AVPlayerStabilityTest() { ...@@ -761,19 +761,7 @@ export default function AVPlayerStabilityTest() {
}) })
/* *
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_SOURCE_0300
* @tc.name : 001.test play source 4k
* @tc.desc : Local Video play source
* @tc.size : MediumTest
* @tc.type : Function test
* @tc.level : Level2
*/
it('SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_SOURCE_0300', 0, async function (done) {
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_SOURCE_0300 start')
AVPlayerTestBase.avPlayerPlay(videos[43], avPlayer, done);
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_SOURCE_0300 end')
})
/* * /* *
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVPLAYER_STABILITY_01_0100 * @tc.number : SUB_MULTIMEDIA_MEDIA_AVPLAYER_STABILITY_01_0100
...@@ -895,11 +883,11 @@ export default function AVPlayerStabilityTest() { ...@@ -895,11 +883,11 @@ export default function AVPlayerStabilityTest() {
* @tc.type : Function test * @tc.type : Function test
* @tc.level : Level3 * @tc.level : Level3
*/ */
// it('SUB_MULTIMEDIA_MEDIA_AVPLAYER_PERFORMANCE_01_0100', 0, async function (done) { // it('SUB_MULTIMEDIA_MEDIA_AVPLAYER_PERFORMANCE_01_0100', 0, async function (done) {
// console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_PERFORMANCE_01_0100 start') // console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_PERFORMANCE_01_0100 start')
// AVPlayerTestBase.createTimeWithCallback(videos[0], avPlayer, done); // AVPlayerTestBase.createTimeWithCallback(videos[0], avPlayer, done);
// console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_PERFORMANCE_01_0100 end') // console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_PERFORMANCE_01_0100 end')
// }) // })
/* * /* *
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVPLAYER_PERFORMANCE_01_0110 * @tc.number : SUB_MULTIMEDIA_MEDIA_AVPLAYER_PERFORMANCE_01_0110
...@@ -1237,5 +1225,19 @@ export default function AVPlayerStabilityTest() { ...@@ -1237,5 +1225,19 @@ export default function AVPlayerStabilityTest() {
AVPlayerTestBase.firstFrameTime(videos[0], avPlayer, done); AVPlayerTestBase.firstFrameTime(videos[0], avPlayer, done);
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_PERFORMANCE_02_0100 end') console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_PERFORMANCE_02_0100 end')
}) })
/* *
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_SOURCE_0300
* @tc.name : 001.test play source 4k
* @tc.desc : Local Video play source
* @tc.size : MediumTest
* @tc.type : Function test
* @tc.level : Level2
*/
it('SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_SOURCE_0300', 0, async function (done) {
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_SOURCE_0300 start')
AVPlayerTestBase.avPlayerPlay(videos[43], avPlayer, done);
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVPLAYER_FORMAT_SOURCE_0300 end')
})
}) })
} }
\ No newline at end of file
...@@ -19,6 +19,7 @@ import AVPlayerLocalTest from './AVPlayerLocalTest.test.js' ...@@ -19,6 +19,7 @@ import AVPlayerLocalTest from './AVPlayerLocalTest.test.js'
import AVPlayerStabilityTest from './AVPlayerStabilityTest.test.js' import AVPlayerStabilityTest from './AVPlayerStabilityTest.test.js'
import AvPlayerEnumTest from './AvPlayerEnumTest.test.js' import AvPlayerEnumTest from './AvPlayerEnumTest.test.js'
export default function testsuite() { export default function testsuite() {
// AVPlayerHlsFuncTest() // AVPlayerHlsFuncTest()
// AVPlayerHttpCompatibilityTest(); // AVPlayerHttpCompatibilityTest();
......
/* /**
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -12,506 +12,147 @@ ...@@ -12,506 +12,147 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import media from '@ohos.multimedia.media'
import * as mediaTestBase from '../../../../../MediaTestBase.js'; import * as mediaTestBase from '../../../../../MediaTestBase.js';
import media from '@ohos.multimedia.media'; import * as avRecorderTestBase from '../../../../../AVRecorderTestBase.js';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; 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 RECORDER_TIME = 3000;
const PAUSE_TIME = 1000; const FORMAT_M4A = media.ContainerFormatType.CFT_MPEG_4A;
const END = 0; const ENCORDER_AAC = media.CodecMimeType.AUDIO_AAC;
const CREATE_PROMISE = 1; const ONLYAUDIO_TYPE = 'only_audio';
const CREATE_CALLBACK = 2; let trackArray;
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;
let fdObject; let fdObject;
let playerSurfaceId = ''; let fdPath;
let avRecorder = null;
let surfaceID = '';
let needDone = false;
let TAG = "[AudioRecorderLocalTest] ";
let avProfile = { let avProfile = {
audioBitrate : 48000, audioBitrate : 48000,
audioChannels : 2, audioChannels : 2,
audioCodec : media.CodecMimeType.AUDIO_AAC,
audioSampleRate : 48000, audioSampleRate : 48000,
fileFormat : media.ContainerFormatType.CFT_MPEG_4, audioCodec : ENCORDER_AAC,
videoBitrate : 48000, fileFormat : FORMAT_M4A,
videoCodec : media.CodecMimeType.VIDEO_MPEG4,
videoFrameWidth : 640,
videoFrameHeight : 480,
videoFrameRate : 30
} }
let avConfig = { let avConfig = {
audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC,
videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV,
profile : avProfile, profile : avProfile,
url : 'fd://', url : 'fd://',
rotation : 0, rotation : 0,
location : { latitude : 30, longitude : 130 } 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 () { beforeAll(async function () {
console.info('beforeAll case In'); console.info('beforeAll in1');
let permissionName1 = 'ohos.permission.MICROPHONE'; let permissionName1 = 'ohos.permission.MICROPHONE';
let permissionName2 = 'ohos.permission.MEDIA_LOCATION'; let permissionName2 = 'ohos.permission.MEDIA_LOCATION';
let permissionName3 = 'ohos.permission.READ_MEDIA'; let permissionName3 = 'ohos.permission.READ_MEDIA';
let permissionName4 = 'ohos.permission.WRITE_MEDIA'; let permissionName4 = 'ohos.permission.WRITE_MEDIA';
let permissionName5 = 'ohos.permission.CAMERA'; let permissionNames = [permissionName1, permissionName2, permissionName3, permissionName4];
let permissionNames = [permissionName1, permissionName2, permissionName3, permissionName4, permissionName5];
await mediaTestBase.getPermission(permissionNames); await mediaTestBase.getPermission(permissionNames);
await mediaTestBase.msleepAsync(2000); await mediaTestBase.msleepAsync(5000);
await mediaTestBase.driveFn(3); console.info('beforeAll out');
console.info('beforeAll case Out');
}) })
beforeEach(async function () { beforeEach(function () {
console.info('beforeEach case In'); console.info('beforeEach case');
playerSurfaceId = globalThis.value;
avRecorder = undefined;
surfaceID = '';
caseCount += 1;
needDone = false;
console.info('beforeEach case Out');
}) })
afterEach(async function () { afterEach(async function () {
console.info('afterEach case In'); console.info('afterEach case');
mySteps = new Array();
await releaseByPromise();
await mediaTestBase.closeFd(fdObject.fileAsset, fdObject.fdNumber);
console.info('afterEach case Out');
}) })
afterAll(function () { afterAll(function () {
mediaTestBase.closeFd(fdObject.fileAsset, fdObject.fdNumber);
console.info('afterAll case'); console.info('afterAll case');
}) })
async function getRecorderFileFd(fileName, fileType) { /* *
console.info("case current fileName is: " + fileName); * @tc.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_AUDIO_FUNCTION_0100
fdObject = await mediaTestBase.getAvRecorderFd(fileName, fileType); * @tc.name : 001.test pause
fdPath = "fd://" + fdObject.fdNumber.toString(); * @tc.desc : Local Video 001.pause
console.info("case fdPath is: " + fdPath); * @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; avConfig.url = fdPath;
console.info("case to out getRecorderFileFd"); avRecorderTestBase.avRecorderWithCallBack(avConfig, avRecorder, RECORDER_TIME, done);
} console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_AUDIO_FUNCTION_0100 end')
})
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'); * @tc.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0100
if (avRecorder != undefined) { * @tc.name : 001.test pause->prepare
console.info('case to call avRecorder.off("stateChange")'); * @tc.desc : Local Video 01.pause->prepare
avRecorder.off('stateChange'); * @tc.size : MediumTest
console.info('case to call avRecorder.off("error")'); * @tc.type : Function test
avRecorder.off('error'); * @tc.level : Level2
console.info('case call avRecorder.off done'); */
} it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0100', 0, async function (done) {
needDone = true; console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0100 start')
nextStep(done); fdObject = await mediaTestBase.getAvRecorderFd(AV_SOURCES[1], "audio");
console.info('case callback off done'); 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.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0200
* @tc.name : 01. test only avRecorder basic function by promise interfaces * @tc.name : 001.test prepare without callback
* @tc.desc : test only avRecorder operation: start-pause-resume-stop * @tc.desc : Local Video prepare without callback
* @tc.size : MediumTest * @tc.size : MediumTest
* @tc.type : Function * @tc.type : Function test
* @tc.level : Level0 * @tc.level : Level2
*/ */
it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_FUNC_0100', 0, async function (done) { it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0200', 0, async function (done) {
avConfig = audioConfig; console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0200 start')
caseCount = 1; fdObject = await mediaTestBase.getAvRecorderFd(AV_SOURCES[2], "audio");
let fileName = 'avRecorder_func_0'+ caseCount +'.m4a'; fdPath = "fd://" + fdObject.fdNumber;
await getRecorderFileFd(fileName, 'audio'); avConfig.url = fdPath;
mySteps = new Array(CREATE_PROMISE, PREPARE_PROMISE, START_PROMISE, PAUSE_PROMISE, avRecorderTestBase.avRecorderReliabilitTest02(avConfig, avRecorder, RECORDER_TIME, done);
RESUME_PROMISE, STOP_PROMISE, RESET_PROMISE, SETCALLBACKOFF, RELEASE_PROMISE); console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0200 end')
nextStep(done);
}) })
/* * /* *
* @tc.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_FUNC_0200 * @tc.number : SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0300
* @tc.name : 01. test only avRecorder basic function by callback interfaces * @tc.name : 001.test prepare with callback
* @tc.desc : test only avRecorder operation: start-pause-resume-stop * @tc.desc : Local Video prepare with callback
* @tc.size : MediumTest * @tc.size : MediumTest
* @tc.type : Function * @tc.type : Function test
* @tc.level : Level0 * @tc.level : Level2
*/ */
it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_FUNC_0200', 0, async function (done) { it('SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0300', 0, async function (done) {
let fileName = 'avRecorder_func_0'+ caseCount +'.m4a'; console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0300 start')
await getRecorderFileFd(fileName, 'audio'); fdObject = await mediaTestBase.getAvRecorderFd(AV_SOURCES[3], "audio");
mySteps = new Array(CREATE_CALLBACK, PREPARE_CALLBACK, START_CALLBACK, PAUSE_CALLBACK, fdPath = "fd://" + fdObject.fdNumber;
RESUME_CALLBACK, STOP_CALLBACK, RESET_CALLBACK, SETCALLBACKOFF, RELEASE_CALLBACK); avConfig.url = fdPath;
nextStep(done); avRecorderTestBase.avRecorderReliabilitTest03(avConfig, avRecorder, RECORDER_TIME, done);
console.info(TAG + 'SUB_MULTIMEDIA_MEDIA_AVRECORDER_PREPARE_API_0300 end')
}) })
}) })
} }
/* /**
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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
...@@ -243,7 +243,7 @@ describe('VideoPlayerFuncCallbackTest', function () { ...@@ -243,7 +243,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
videoPlayer.getTrackDescription((err, arrlist) => { videoPlayer.getTrackDescription((err, arrlist) => {
if (err == null) { if (err == null) {
for (let i = 0; i < arrlist.length; i++) { for (let i = 0; i < arrlist.length; i++) {
mediaTestBase.checkDescription(arrlist[i], descriptionKey[i], descriptionValue[i]); mediaTestBase.checkOldDescription(arrlist[i], descriptionKey[i], descriptionValue[i]);
} }
toNextStep(videoPlayer, steps, done); toNextStep(videoPlayer, steps, done);
} else if ((err != null) && (steps[0] == ERROR_EVENT)) { } else if ((err != null) && (steps[0] == ERROR_EVENT)) {
......
...@@ -509,7 +509,7 @@ describe('VideoPlayerFuncPromiseTest', function () { ...@@ -509,7 +509,7 @@ describe('VideoPlayerFuncPromiseTest', function () {
}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback); }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
for (let i = 0; i < arrayDescription.length; i++) { for (let i = 0; i < arrayDescription.length; i++) {
mediaTestBase.checkDescription(arrayDescription[i], descriptionKey[i], descriptionValue[i]); mediaTestBase.checkOldDescription(arrayDescription[i], descriptionKey[i], descriptionValue[i]);
} }
await videoPlayer.release().then(() => { await videoPlayer.release().then(() => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册