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

!3056 公共函数提取

Merge pull request !3056 from NOBUGGERS/r00514670_0425
......@@ -16,11 +16,13 @@
import resourceManager from '@ohos.resourceManager';
import {expect} from 'deccjsunit/index'
// File operation
export async function getFileDescriptor(fileName) {
let fileDescriptor = undefined;
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.getRawFileDescriptor(fileName).then(value => {
fileDescriptor = {fd: value.fd, offset: value.offset, length: value.length};
console.log('case getRawFileDescriptor success fileName: ' + fileName);
}).catch(error => {
console.log('case getRawFileDescriptor err: ' + error);
});
......@@ -30,8 +32,8 @@ export async function getFileDescriptor(fileName) {
export async function closeFileDescriptor(fileName) {
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.closeRawFileDescriptor(fileName).then(value => {
console.log('case closeRawFileDescriptor ' + value);
await mgr.closeRawFileDescriptor(fileName).then(()=> {
console.log('case closeRawFileDescriptor ' + fileName);
}).catch(error => {
console.log('case closeRawFileDescriptor err: ' + error);
});
......@@ -44,4 +46,42 @@ export function isFileOpen(fileDescriptor, done) {
console.info('case error fileDescriptor undefined, open file fail');
done();
}
}
// wait synchronously
export function msleep(time) {
for(let t = Date.now();Date.now() - t <= time;);
}
// wait asynchronously
export async function msleepAsync(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
export function printError(error, done) {
expect().assertFail();
console.info(`case error called,errMessage is ${error.message}`);
done();
}
// callback function for promise call back error
export function failureCallback(error) {
expect().assertFail();
console.info(`case error called,errMessage is ${error.message}`);
}
// callback function for promise catch error
export function catchCallback(error) {
expect().assertFail();
console.info(`case error called,errMessage is ${error.message}`);
}
export function printDescription(obj) {
let description = "";
for(let i in obj) {
let property = obj[i];
console.info('case key is '+ i);
console.info('case value is '+ property);
description += i + " = " + property + "\n";
}
}
\ No newline at end of file
......@@ -14,7 +14,7 @@
*/
import media from '@ohos.multimedia.media'
import {getFileDescriptor, closeFileDescriptor, isFileOpen} from '../../../../../MediaTestBase.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('PlayerLocalTestAudioAPI', function () {
......@@ -49,14 +49,14 @@ describe('PlayerLocalTestAudioAPI', function () {
beforeEach(async function() {
isTimeOut = false;
await getFileDescriptor(AUDIO_SOURCE).then((res) => {
await mediaTestBase.getFileDescriptor(AUDIO_SOURCE).then((res) => {
fileDescriptor = res;
});
console.info('beforeEach case');
})
afterEach(async function() {
await closeFileDescriptor(AUDIO_SOURCE);
await mediaTestBase.closeFileDescriptor(AUDIO_SOURCE);
console.info('afterEach case');
})
......@@ -64,10 +64,6 @@ describe('PlayerLocalTestAudioAPI', function () {
console.info('afterAll case');
})
function sleep(time) {
for(let t = Date.now();Date.now() - t <= time;);
}
function initAudioPlayer() {
if (typeof (audioPlayer) != 'undefined') {
audioPlayer.release();
......@@ -147,7 +143,7 @@ describe('PlayerLocalTestAudioAPI', function () {
audioPlayer.on('play', () => {
mySteps.shift();
console.info(`case play called`);
sleep(PLAY_TIME);
mediaTestBase.msleep(PLAY_TIME);
console.info(`case play currentTime is ${audioPlayer.currentTime}`);
expect(audioPlayer.duration).assertEqual(DURATION_TIME);
if (mySteps[0] == FINISH_STATE) {
......@@ -199,7 +195,7 @@ describe('PlayerLocalTestAudioAPI', function () {
console.info(`case loop is ${audioPlayer.loop}`);
if ((audioPlayer.loop == true) && (seekDoneTime == DURATION_TIME)) {
console.info('case loop is true');
sleep(PLAY_STATE);
mediaTestBase.msleep(PLAY_STATE);
}
if ((seekDoneTime < audioPlayer.duration) || (audioPlayer.state == 'paused')) {
nextStep(mySteps,done);
......@@ -210,7 +206,7 @@ describe('PlayerLocalTestAudioAPI', function () {
mySteps.shift();
mySteps.shift();
if (audioPlayer.state == 'playing') {
sleep(PLAY_TIME);
mediaTestBase.msleep(PLAY_TIME);
}
nextStep(mySteps,done);
});
......@@ -252,7 +248,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_SRC_API_0100', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
fileDescriptor.fd = -1;
let mySteps = new Array(ERROR_STATE, END_STATE);
initAudioPlayer();
......@@ -269,7 +265,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_SRC_API_0200', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
fileDescriptor.offset = 1;
let mySteps = new Array(SRC_STATE, PLAY_STATE, PAUSE_STATE, PLAY_STATE, END_STATE);
initAudioPlayer();
......@@ -286,7 +282,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_SRC_API_0300', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
fileDescriptor.length = -1;
let mySteps = new Array(SRC_STATE, PLAY_STATE, PAUSE_STATE, PLAY_STATE, END_STATE);
initAudioPlayer();
......@@ -303,7 +299,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_SRC_API_0400', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(ERROR_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -319,7 +315,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Play_API_0100', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
console.info(`case update`);
let mySteps = new Array(SRC_STATE, PLAY_STATE, PAUSE_STATE, PLAY_STATE, END_STATE);
initAudioPlayer();
......@@ -336,7 +332,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Play_API_0200', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, STOP_STATE, PLAY_STATE, ERROR_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -352,7 +348,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Play_API_0300', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, PAUSE_STATE, SEEK_STATE, SEEK_TIME, PLAY_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -368,7 +364,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Play_API_0400', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, RESET_STATE, PLAY_STATE, ERROR_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -384,7 +380,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Pause_API_0100', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(PAUSE_STATE, ERROR_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -400,7 +396,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Pause_API_0200', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, PAUSE_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -416,7 +412,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Pause_API_0300', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(PLAY_STATE, STOP_STATE, PAUSE_STATE, ERROR_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -432,7 +428,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Pause_API_0400', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, SEEK_STATE, SEEK_TIME, PAUSE_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -448,7 +444,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Stop_API_0100', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, STOP_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -464,7 +460,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Stop_API_0200', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, PAUSE_STATE, STOP_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -480,7 +476,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Stop_API_0300', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, SEEK_STATE, SEEK_TIME, STOP_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -496,7 +492,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Seek_API_0100', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, SEEK_STATE, SEEK_TIME, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -512,7 +508,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Seek_API_0200', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, PAUSE_STATE, SEEK_STATE, SEEK_TIME, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -528,7 +524,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Seek_API_0300', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, SEEK_STATE, 0, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -544,7 +540,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Reset_API_0100', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, RESET_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -560,7 +556,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Reset_API_0200', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, PAUSE_STATE, RESET_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -576,7 +572,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_SetVolume_API_0100', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
var mySteps = new Array(VOLUME_STATE, VOLUME_VALUE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -592,7 +588,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_SetVolume_API_0200', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
var mySteps = new Array(SRC_STATE, PLAY_STATE, VOLUME_STATE, VOLUME_VALUE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -608,7 +604,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_SetVolume_API_0300', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
var mySteps = new Array(SRC_STATE, PLAY_STATE, PAUSE_STATE, VOLUME_STATE, VOLUME_VALUE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -624,7 +620,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Release_API_0100', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, RELEASE_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -640,7 +636,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Release_API_0200', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, PAUSE_STATE, RELEASE_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -656,7 +652,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Release_API_0300', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, STOP_STATE, RELEASE_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -672,7 +668,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Release_API_0400', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, SEEK_STATE, SEEK_TIME, RELEASE_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -688,7 +684,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Release_API_0400', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let mySteps = new Array(SRC_STATE, PLAY_STATE, RESET_STATE, RELEASE_STATE, END_STATE);
initAudioPlayer();
setCallback(mySteps, done);
......@@ -704,7 +700,7 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Time_API_0100', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
initAudioPlayer();
expect(audioPlayer.src).assertEqual(undefined);
expect(audioPlayer.duration).assertEqual(undefined);
......@@ -723,10 +719,10 @@ describe('PlayerLocalTestAudioAPI', function () {
* @tc.level : Level2
*/
it('SUB_MEDIA_PLAYER_AudioPlayer_Time_API_0200', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
initAudioPlayer();
audioPlayer.src = fdHead + fileDescriptor.fd;
sleep(PLAY_TIME);
mediaTestBase.msleep(PLAY_TIME);
expect(audioPlayer.src).assertEqual(fdHead + fileDescriptor.fd);
expect(audioPlayer.currentTime).assertEqual(0);
expect(audioPlayer.duration).assertEqual(DURATION_TIME);
......
......@@ -14,7 +14,7 @@
*/
import media from '@ohos.multimedia.media'
import {getFileDescriptor, closeFileDescriptor, isFileOpen} from '../../../../../MediaTestBase.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('PlayerLocalTestAudioFormat', function () {
......@@ -41,21 +41,17 @@ describe('PlayerLocalTestAudioFormat', function () {
})
afterAll(async function() {
await closeFileDescriptor(audioSource);
await mediaTestBase.closeFileDescriptor(audioSource);
console.info('afterAll case');
})
function sleep(time) {
for(let t = Date.now(); Date.now() - t <= time;);
}
async function playSource(audioFile, done) {
let audioPlayer = media.createAudioPlayer();
audioSource = audioFile;
await getFileDescriptor(audioSource).then((res) => {
await mediaTestBase.getFileDescriptor(audioSource).then((res) => {
fileDescriptor = res;
});
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
audioPlayer.src = 'fd://' + fileDescriptor.fd;
audioPlayer.on('dataLoad', () => {
console.info('case set source success');
......@@ -66,7 +62,7 @@ describe('PlayerLocalTestAudioFormat', function () {
audioPlayer.on('play', () => {
console.info('case start to play');
expect(audioPlayer.state).assertEqual('playing');
sleep(PLAY_TIME);
mediaTestBase.msleep(PLAY_TIME);
if (!isToSeek) {
audioPlayer.pause();
} else {
......@@ -102,7 +98,7 @@ describe('PlayerLocalTestAudioFormat', function () {
if (!isToDuration) {
expect(SEEK_TIME).assertEqual(seekDoneTime);
isToDuration = true;
sleep(PLAY_TIME);
mediaTestBase.msleep(PLAY_TIME);
audioPlayer.seek(audioPlayer.duration);
} else {
expect(audioPlayer.duration).assertEqual(seekDoneTime);
......
......@@ -15,7 +15,7 @@
import media from '@ohos.multimedia.media'
import {toNewPage, clearRouter} from './VideoPlayerTestBase.js';
import {getFileDescriptor, closeFileDescriptor, isFileOpen} from '../../../../../MediaTestBase.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('VideoPlayerFuncCallbackTest', function () {
......@@ -58,7 +58,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
beforeAll(async function() {
console.info('beforeAll case');
await getFileDescriptor(VIDEO_SOURCE).then((res) => {
await mediaTestBase.getFileDescriptor(VIDEO_SOURCE).then((res) => {
fileDescriptor = res;
});
})
......@@ -66,7 +66,8 @@ describe('VideoPlayerFuncCallbackTest', function () {
beforeEach(async function() {
await toNewPage(page);
page = (page + 1) % 2;
await msleep(1000).then(() => {}, failureCallback).catch(catchCallback);
await mediaTestBase.msleepAsync(1000).then(
() => {}, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
surfaceID = globalThis.value;
console.info('case new surfaceID is ' + surfaceID);
console.info('beforeEach case');
......@@ -78,44 +79,10 @@ describe('VideoPlayerFuncCallbackTest', function () {
})
afterAll(async function() {
await closeFileDescriptor(VIDEO_SOURCE);
await mediaTestBase.closeFileDescriptor(VIDEO_SOURCE);
console.info('afterAll case');
})
function failureCallback(error) {
expect().assertFail();
console.info(`case error called,errMessage is ${error.message}`);
}
function catchCallback(error) {
expect().assertFail();
console.info(`case error called,errMessage is ${error.message}`);
}
function sleep(time) {
for(let t = Date.now(); Date.now() - t <= time;);
}
function msleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function printfError(error, done) {
expect().assertFail();
console.info(`case error called,errMessage is ${error.message}`);
done();
}
function printfDescription(obj) {
let description = "";
for(let i in obj) {
let property = obj[i];
console.info('case key is '+ i);
console.info('case value is '+ property);
description += i + " = " + property + "\n";
}
}
function toNextStep(videoPlayer, steps, done) {
if (steps[0] == END_EVENT) {
console.info('case success!!');
......@@ -164,7 +131,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -192,7 +159,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
eventEmitter.on(WAIT_EVENT, (videoPlayer, steps, done) => {
steps.shift();
sleep(PLAY_TIME);
mediaTestBase.msleep(PLAY_TIME);
toNextStep(videoPlayer, steps, done);
});
......@@ -207,7 +174,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
})
});
......@@ -226,7 +193,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -245,7 +212,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -255,14 +222,14 @@ describe('VideoPlayerFuncCallbackTest', function () {
videoPlayer.getTrackDescription((err, arrlist) => {
if (typeof (err) == 'undefined') {
for (let i = 0; i < arrlist.length; i++) {
printfDescription(arrlist[i]);
mediaTestBase.printDescription(arrlist[i]);
}
toNextStep(videoPlayer, steps, done);
} else if ((typeof (err) != 'undefined') && (steps[0] == ERROR_EVENT)) {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -274,7 +241,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
if (typeof (err) == 'undefined') {
expect(videoPlayer.state).assertEqual('playing');
console.info('case play success!!');
sleep(PLAY_TIME);
mediaTestBase.msleep(PLAY_TIME);
let endTime = videoPlayer.currentTime;
expect(endTime - startTime).assertClose(PLAY_TIME, DELTA_TIME);
toNextStep(videoPlayer, steps, done);
......@@ -282,7 +249,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -298,7 +265,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -314,7 +281,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -330,7 +297,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -345,7 +312,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -391,7 +358,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -414,7 +381,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -431,7 +398,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -468,7 +435,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
let startTime = videoPlayer.currentTime;
videoPlayer.setSpeed(speedValue, (err, speedMode) => {
if (typeof (err) == 'undefined') {
sleep(1000);
mediaTestBase.msleep(1000);
expect(speedValue).assertEqual(speedMode);
console.info('case setSpeed success and speedMode is '+ speedMode);
checkSpeedTime(videoPlayer, speedValue, startTime);
......@@ -477,7 +444,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
steps.shift();
toNextStep(videoPlayer, steps, done);
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -491,7 +458,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
* @tc.level : Level0
*/
it('SUB_MEDIA_VIDEO_PLAYER_FUNCTION_PROMISE_SETSOURCE', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let videoPlayer = null;
let fdPath = '';
let mySteps = new Array(CREATE_EVENT, SETSOURCE_EVENT, fdPath, ERROR_EVENT, RELEASE_EVENT, END_EVENT);
......@@ -507,7 +474,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
* @tc.level : Level0
*/
it('SUB_MEDIA_VIDEO_PLAYER_FUNCTION_CALLBACK_SETVOLUME', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let videoPlayer = null;
let mySteps = new Array(CREATE_EVENT, SETFDSOURCE_EVENT, fileDescriptor, SETSURFACE_EVENT,
PREPARE_EVENT, PLAY_EVENT, SETVOLUME_EVENT, 0, SETVOLUME_EVENT, 0.5, SETVOLUME_EVENT, 1,
......@@ -524,7 +491,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
* @tc.level : Level0
*/
it('SUB_MEDIA_VIDEO_PLAYER_FUNCTION_CALLBACK_SETSPEED', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let videoPlayer = null;
let mySteps = new Array(CREATE_EVENT, SETFDSOURCE_EVENT, fileDescriptor, SETSURFACE_EVENT,
PREPARE_EVENT, PLAY_EVENT, SETSPEED_EVENT, media.PlaybackSpeed.SPEED_FORWARD_0_75_X,
......@@ -544,7 +511,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
* @tc.level : Level0
*/
it('SUB_MEDIA_VIDEO_PLAYER_FUNCTION_CALLBACK_SEEKMODE', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let videoPlayer = null;
let mySteps = new Array(CREATE_EVENT, SETFDSOURCE_EVENT, fileDescriptor, SETSURFACE_EVENT,
PREPARE_EVENT, PLAY_EVENT, SEEK_MODE_EVENT, SEEK_TIME, media.SeekMode.SEEK_NEXT_SYNC,
......@@ -561,7 +528,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
* @tc.level : Level0
*/
it('SUB_MEDIA_VIDEO_PLAYER_FUNCTION_CALLBACK_CALLBACK', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let videoPlayer = null;
let frameCount = -1;
let completedCount = 0;
......@@ -576,7 +543,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
console.info('case createVideoPlayer success!!');
eventEmitter.emit('test_callback');
}else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -593,7 +560,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
console.info('case release success!!');
done();
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -623,7 +590,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
console.info('case setDisplaySurface success!!');
eventEmitter.emit('test_prepare');
}else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
})
});
......@@ -638,7 +605,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
console.info('case prepare success!!');
eventEmitter.emit('test_play');
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -649,7 +616,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
expect(videoPlayer.state).assertEqual('playing');
console.info('case play success!!');
} else {
printfError(err, done);
mediaTestBase.printError(err, done);
}
});
});
......@@ -665,7 +632,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
* @tc.level : Level0
*/
it('SUB_MEDIA_VIDEO_PLAYER_FUNCTION_CALLBACK_GETTRECKDESCRIPTION', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let videoPlayer = null;
let mySteps = new Array(CREATE_EVENT, SETFDSOURCE_EVENT, fileDescriptor, SETSURFACE_EVENT,
PREPARE_EVENT, GETDESCRIPTION, RELEASE_EVENT, END_EVENT);
......@@ -681,7 +648,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
* @tc.level : Level0
*/
it('SUB_MEDIA_VIDEO_PLAYER_FUNCTION_CALLBACK_LOOP', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let videoPlayer = null;
let mySteps = new Array(CREATE_EVENT, SETFDSOURCE_EVENT, fileDescriptor, SETSURFACE_EVENT,
PREPARE_EVENT, SETLOOP_EVENT, true, PLAY_EVENT, SEEK_EVENT, DURATION_TIME, WAIT_EVENT,
......@@ -699,7 +666,7 @@ describe('VideoPlayerFuncCallbackTest', function () {
* @tc.level : Level0
*/
it('SUB_MEDIA_VIDEO_PLAYER_FUNCTION_CALLBACK_BASE', 0, async function (done) {
isFileOpen(fileDescriptor, done);
mediaTestBase.isFileOpen(fileDescriptor, done);
let videoPlayer = null;
let fdPath = fdHead + fileDescriptor.fd;
let mySteps = new Array(CREATE_EVENT, SETFDSOURCE_EVENT, fileDescriptor, SETSURFACE_EVENT,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册