You need to sign in or sign up before continuing.
提交 16a61478 编写于 作者: O openharmony_ci 提交者: Gitee

!459 【媒体子系统】【Audio子模块】-L2JS测试代码上库

Merge pull request !459 from tianfenxia/master
......@@ -19,7 +19,8 @@ group("multimedia") {
deps = [
"audio/audio_js_standard/audioPlayer:audio_player_js_hap" ,
"audio/audio_js_standard/audioPlayer_API:audio_player_api_js_hap",
"media/media_cpp_test_standard:ActsMediaCppStandardTest",
"audio/audio_js_standard/audioManager:audio_manager_js_hap",
"media/media_cpp_test_standard:ActsMediaCppStandardTest"
]
} else {
deps = [
......
......@@ -12,7 +12,7 @@
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("audio_manager_js_test") {
ohos_js_hap_suite("audio_manager_js_hap") {
test_hap_name = "AudioManagerJsTest"
hap_source_path = "hap/entry-debug-rich-signed.hap"
hap_source_path = "hap/AudioManager.hap"
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import audio from '@ohos.multimedia.audio';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioManager.test.js', function () {
const audioManager = audio.getAudioManager();
var maxVolume = 1;
var minVolume = 0;
var deviceTypeValue = null;
var deviceRoleValue = null;
beforeAll(function () {
console.info('beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.');
})
beforeEach(function () {
console.info('beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.');
})
afterEach(function () {
console.info('afterEach: Test case-level clearance conditions, which are executed after each test case is executed.');
})
afterAll(function () {
console.info('afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed');
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_SetVolume_001
* @tc.name : Set Audiomanager with volume type media 01
* @tc.desc : Audiomanager SetVolume media-success
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_SetVolume_001', 0, function () {
audioManager.setVolume(1, 12).then(function (data) {
console.info('Media setVolume successful promise');
audioManager.getVolume(1).then(function (data) {
console.info('Media getVolume promise ' + data);
expect(data).assertEqual(12);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_SetVolume_001 : PASS');
});
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_SetVolume_002
* @tc.name : Set Audiomanager with volume type ringtone 02
* @tc.desc : Audiomanager SetVolume media-success
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_SetVolume_002', 0, function () {
audioManager.setVolume(2, 11).then(function (data) {
console.info('Media setVolume successful promise ');
audioManager.getVolume(2).then(function (data) {
console.info('Media getVolume promise ' + data);
expect(data).assertEqual(11);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_SetVolume_002 : PASS');
});
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_SetVolume_003
* @tc.name : Set Audiomanager with volume type media and callback
* @tc.desc : Audiomanager SetVolume media-success
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_SetVolume_003', 0, function () {
audioManager.setVolume(1, 10, (err, value) => {
if (err) {
console.error(`failed to set volume ${err.message}`);
return;
}
console.log(`Media setVolume successful callback`);
audioManager.getVolume(1, (err, value) => {
if (err) {
console.error(`failed to get volume ${err.message}`);
return;
}
console.log(`Media getVolume ${value}`);
expect(value).assertEqual(10);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_SetVolume_003 : PASS');
});
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_SetVolume_004
* @tc.name : Set Audiomanager with volume type ringtone and callback
* @tc.desc : Audiomanager should set the volume as per the API and return it from Get API
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_SetVolume_004', 0, function () {
audioManager.setVolume(2, 13, (err, value) => {
if (err) {
console.error(`failed to set volume ${err.message}`);
return;
}
console.log(`Media setVolume successful callback`);
audioManager.getVolume(1, (err, value) => {
if (err) {
console.error(`failed to get volume ${err.message}`);
return;
}
console.log(`Media getVolume ${value}`);
expect(value).assertEqual(13);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_SetVolume_004 : PASS');
});
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_SetVolume_005
* @tc.name : Set Audiomanager with volume level beyond maxvolume
* @tc.desc : Audiomanager should return an error for setting the volume
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_SetVolume_005', 0, function () {
audioManager.setVolume(2, 16, (err, value) => {
if (err) {
console.error(`failed to set volume ${err.message}`);
return;
}
audioManager.getVolume(2, (err, value) => {
if (err) {
console.error(`failed to get volume ${err.message}`);
return;
}
console.log(`Media getVolume ${value}`);
if (value != 16) {
expect(true).assertTrue();
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_SetVolume_005 : PASS');
}
});
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_001
* @tc.name : Check Audiomanager get max volume for media
* @tc.desc : Audiomanager get max volume
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_001', 0, function () {
audioManager.getMaxVolume(1).then(function (data) {
console.info('Media getMaxVolume promise ' + data);
expect(data).assertEqual(maxVolume);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_001 : PASS');
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_002
* @tc.name : Check Audiomanager get max volume for ringtone
* @tc.desc : Audiomanager get max volume-ringtone
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_002', 0, function () {
audioManager.getMaxVolume(2).then(function (data) {
console.info('Media getMaxVolume promise ' + data);
expect(data).assertEqual(maxVolume);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_002 : PASS');
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_003
* @tc.name : Check Audiomanager get max volume for media with callback
* @tc.desc : Audiomanager get max volume
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_003', 0, function () {
audioManager.getMaxVolume(1, (err, value) => {
if (err) {
console.error(`failed to get volume ${err.message}`);
return;
}
console.log(`Media getMaxVolume ${value}`);
expect(value).assertEqual(maxVolume);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_003 : PASS');
});
});
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_004
* @tc.name : Check Audiomanager get max volume for ringtone with callback
* @tc.desc : Audiomanager get max volume - rigtone
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_004', 0, function () {
audioManager.getMaxVolume(2, (err, value) => {
if (err) {
console.error(`failed to get volume ${err.message}`);
return;
}
console.log(`Media getMaxVolume ${value}`);
expect(value).assertEqual(maxVolume);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_004 : PASS');
});
});
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_001
* @tc.name : Check Audiomanager get min volume for media
* @tc.desc : Audiomanager get min volume- media
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_001', 0, function () {
audioManager.getMinVolume(1).then(function (data) {
console.info('Media getMinVolume promise ' + data);
expect(data).assertEqual(minVolume);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_001 : PASS');
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_002
* @tc.name : Check Audiomanager get min volume for ringtone
* @tc.desc : Audiomanager get min volume-ringtone
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_002', 0, function () {
audioManager.getMinVolume(2).then(function (data) {
console.info('Media getMinVolume promise ' + data);
expect(data).assertEqual(minVolume);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_002 : PASS');
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_003
* @tc.name : Check Audiomanager get min volume for media with callback
* @tc.desc : Audiomanager get min volume- media
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_003', 0, function () {
audioManager.getMinVolume(1, (err, value) => {
if (err) {
console.error(`failed to get volume ${err.message}`);
return;
}
console.log(`Media getMinVolume ${value}`);
expect(value).assertEqual(minVolume);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_003 : PASS');
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_004
* @tc.name : Check Audiomanager get min volume for ringtone
* @tc.desc : Audiomanager get min volume-ringtone
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_004', 0, function () {
audioManager.getMinVolume(2, (err, value) => {
if (err) {
console.error(`failed to get volume ${err.message}`);
return;
}
console.log(`Media getMinVolume ${value}`);
expect(value).assertEqual(minVolume);
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_004 : PASS');
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_Get_Devices_001
* @tc.name : Check Audiomanager get devices with DEVICES_FLAG 01
* @tc.desc : Audiomanager get device-positive return value
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_001', 0, function () {
deviceRoleValue = null;
deviceTypeValue = null;
audioManager.getDevices(1, (err, value) => {
if (err) {
console.error(`failed to get devices ${err.message}`);
return;
}
console.log('getDevices output devices');
value.forEach(displayDeviceProp);
if (deviceTypeValue != null && deviceRoleValue != null) {
expect(true).assertTrue();
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_001 : PASS');
}
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_Get_Devices_002
* @tc.name : Check Audiomanager get devices with DEVICES_FLAG 02
* @tc.desc : Audiomanager get device-positive return value
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_002', 0, function () {
deviceRoleValue = null;
deviceTypeValue = null;
audioManager.getDevices(2, (err, value) => {
if (err) {
console.error(`failed to get devices ${err.message}`);
return;
}
console.log('getDevices output devices');
value.forEach(displayDeviceProp);
if (deviceTypeValue != null && deviceRoleValue != null) {
expect(true).assertTrue();
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_002 : PASS');
}
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_Get_Devices_003
* @tc.name : Check Audiomanager get devices with DEVICES_FLAG 03
* @tc.desc : Audiomanager get device-positive return value
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_003', 0, function () {
deviceRoleValue = null;
deviceTypeValue = null;
audioManager.getDevices(3, (err, value) => {
if (err) {
console.error(`failed to get devices ${err.message}`);
return;
}
console.log('getDevices All devices');
value.forEach(displayDeviceProp);
if (deviceTypeValue != null && deviceRoleValue != null) {
expect(true).assertTrue();
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_003 : PASS');
}
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetDevice_004
* @tc.name : Check Audiomanager get devices with deviceflag value as 1
* @tc.desc : Audiomanager get getdevices without callback
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_004', 0, function () {
deviceRoleValue = null;
deviceTypeValue = null;
audioManager.getDevices(1).then(function (value) {
value.forEach(displayDeviceProp);
if (deviceTypeValue != null && deviceRoleValue != null) {
expect(true).assertTrue();
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_004 : PASS');
}
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetDevice_005
* @tc.name : Check Audiomanager get devices with deviceflag values as 2
* @tc.desc : Audiomanager get getdevices without callback
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_005', 0, function () {
deviceRoleValue = null;
deviceTypeValue = null;
audioManager.getDevices(2).then(function (value) {
value.forEach(displayDeviceProp);
if (deviceTypeValue != null && deviceRoleValue != null) {
expect(true).assertTrue();
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_005 : PASS');
}
});
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetDevice_006
* @tc.name : Check Audiomanager get devices with deviceflag values as 3
* @tc.desc : Audiomanager get getdevices without callback
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_006', 0, function () {
deviceRoleValue = null;
deviceTypeValue = null;
audioManager.getDevices(3).then(function (value) {
value.forEach(displayDeviceProp);
if (deviceTypeValue != null && deviceRoleValue != null) {
expect(true).assertTrue();
console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_006 : PASS');
}
});
})
function displayDeviceProp(value, index, array) {
console.log(`device role: ${value.deviceRole}`);
deviceRoleValue = value.deviceRole;
console.log(`device type: ${value.deviceType}`);
deviceTypeValue = value.deviceType;
}
})
\ No newline at end of file
......@@ -13,4 +13,4 @@
* limitations under the License.
*/
require('./AudioManager.test.js')
\ No newline at end of file
require('./AudioFramework.test.js')
\ No newline at end of file
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hit/ActsMediaCppStandardTest"
###############################################################################
config("media_cpp_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"//multimedia/media_standard/frameworks/innerkitsimpl/native/player/include",
]
}
ohos_moduletest_suite("ActsMediaCppStandardTest") {
module_out_path = module_output_path
sources = [
"recorder/src/fuction/ActsVideoRecorderTest.cpp",
"recorder/src/fuction/ActsAudioRecoederTest.cpp",
"player/Testplayer.cpp",
"player/src/function/ActsPlayerFuncTest.cpp",
"player/src/function/ActsPlayerFuncAsyncTest.cpp",
"player/src/function/ActsPlayerStateTest.cpp",
"player/src/function/ActsPlayerStateAsyncTest.cpp",
"player/src/api/01.SetSource.cpp",
"player/src/api/02.Prepare.cpp",
"player/src/api/03.Play.cpp",
"player/src/api/04.Pause.cpp",
"player/src/api/05.Stop.cpp",
"player/src/api/06.Reset.cpp",
"player/src/api/07.Seek.cpp",
"player/src/api/08.SetVolume.cpp",
"player/src/api/09.SetLooping.cpp",
"player/src/api/10.SetPlaybackSpeed.cpp",
"player/src/api/11.PrepareAsync.cpp",
"player/src/api/12.GetCurrentTime.cpp",
]
include_dirs = [
"include",
"player/include",
"recorder/include",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include",
]
cflags = [
"-Wall"
]
cflags_cc = cflags
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//foundation/graphic/standard:libwms_client",
"//third_party/googletest:gtest_main",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
]
external_deps = [
"ipc:ipc_core",
"multimedia_media_standard:media_client",
]
configs = [ ":media_cpp_config" ]
}
{
"kits": [
{
"push": [
"ActsMediaCppStandardTest->/data/local/tmp/ActsMediaCppStandardTest"
],
"type": "PushKit",
"post-push": [
"chmod -R 777 /data/local/tmp/*"
]
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsMediaCppStandardTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsMediaCppStandardTest Tests"
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "media_log.h"
#define MEDIA_DEBUG_LOG(fmt, ...) \
do { \
printf(fmt, ##__VA_ARGS__); \
printf("\n"); \
__MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Debug, fmt, ##__VA_ARGS__); \
} while (0) \
#define MEDIA_INFO_LOG(fmt, ...) \
do { \
printf(fmt, ##__VA_ARGS__); \
printf("\n"); \
__MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__); \
} while (0) \
#define MEDIA_ERROR_LOG(fmt, ...) \
do { \
printf(fmt, ##__VA_ARGS__); \
printf("\n"); \
__MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Error, fmt, ##__VA_ARGS__); \
} while (0) \
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "MediaTest"};
}
namespace MediaTest {
constexpr int SURFACE_QUEUE_SIZE = 5;
const float VOLUME = 0.5f;
const int FIRST_ARG_IDX = 1;
const int SECOND_ARG_IDX = 2;
const int THIRD_ARG = 3;
const int HEIGHT = 720;
const int WIDTH = 1280;
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Testplayer.h"
#include "parameter.h"
using namespace OHOS;
using namespace OHOS::Media;
using namespace PlayerNameSpace;
namespace PlayerNameSpace {
std::string GetUri()
{
char path[256] = "/data/1.mp4";
GetParameter("sys.media.test.stream.path", "/data/1.mp4", &path[0], 256);
MEDIA_INFO_LOG("PATH : %s", path);
return path;
}
}
TestPlayer::TestPlayer(PlayerSignal *test)
: test_(test)
{
}
TestPlayer::~TestPlayer()
{
}
bool TestPlayer::CreatePlayer()
{
player = PlayerFactory::CreatePlayer();
if (player == nullptr) {
return false;
}
return true;
}
int32_t TestPlayer::SetSource(const std::string &uri)
{
return player->SetSource(uri);
}
int32_t TestPlayer::Play()
{
int32_t ret = player->Play();
if (test_->mutexFlag_ == true && test_->state_ != PLAYER_STARTED) {
std::unique_lock<std::mutex> lockPlay(test_->mutexPlay_);
test_->condVarPlay_.wait_for(lockPlay, std::chrono::seconds(WAITSECOND));
if (test_->state_ != PLAYER_STARTED) {
return -1;
}
}
return ret;
}
int32_t TestPlayer::Prepare()
{
int32_t ret = player->Prepare();
if (test_->mutexFlag_ == true && test_->state_ != PLAYER_PREPARED) {
std::unique_lock<std::mutex> lockPrepare(test_->mutexPrepare_);
test_->condVarPrepare_.wait_for(lockPrepare, std::chrono::seconds(WAITSECOND));
if (test_->state_ != PLAYER_PREPARED) {
return -1;
}
}
return ret;
}
int32_t TestPlayer::PrepareAsync()
{
int32_t ret = player->PrepareAsync();
if (test_->mutexFlag_ == true && test_->state_ != PLAYER_PREPARED) {
std::unique_lock<std::mutex> lockPrepare(test_->mutexPrepare_);
test_->condVarPrepare_.wait_for(lockPrepare, std::chrono::seconds(WAITSECOND));
if (test_->state_ != PLAYER_PREPARED) {
return -1;
}
}
return ret;
}
int32_t TestPlayer::Pause()
{
int32_t ret = player->Pause();
if (test_->mutexFlag_ == true && test_->state_ != PLAYER_PAUSED) {
std::unique_lock<std::mutex> lockPause(test_->mutexPause_);
test_->condVarPause_.wait_for(lockPause, std::chrono::seconds(WAITSECOND));
if (test_->state_ != PLAYER_PAUSED) {
return -1;
}
}
return ret;
}
int32_t TestPlayer::Stop()
{
int32_t ret = player->Stop();
if (test_->mutexFlag_ == true && test_->state_ != PLAYER_STOPPED) {
std::unique_lock<std::mutex> lockStop(test_->mutexStop_);
test_->condVarStop_.wait_for(lockStop, std::chrono::seconds(WAITSECOND));
if (test_->state_ != PLAYER_STOPPED) {
return -1;
}
}
return ret;
}
int32_t TestPlayer::Reset()
{
int32_t ret = player->Reset();
if (test_->mutexFlag_ == true && test_->state_ != PLAYER_IDLE) {
std::unique_lock<std::mutex> lockReset(test_->mutexReset_);
test_->condVarReset_.wait_for(lockReset, std::chrono::seconds(WAITSECOND));
if (test_->state_ != PLAYER_IDLE) {
return -1;
}
}
return ret;
}
int32_t TestPlayer::Release()
{
return player->Release();
}
int32_t TestPlayer::SetVolume(float leftVolume, float rightVolume)
{
return player->SetVolume(leftVolume, rightVolume);
}
int32_t TestPlayer::Seek(int32_t mseconds, PlayerSeekMode mode)
{
test_->seekDoneFlag_ = false;
test_->seekPositon_ = mseconds;
int32_t ret = player->Seek(mseconds, mode);
if (test_->mutexFlag_ == true && test_->seekDoneFlag_ == false) {
std::unique_lock<std::mutex> lockSeek(test_->mutexSeek_);
test_->condVarSeek_.wait_for(lockSeek, std::chrono::seconds(WAITSECOND));
if (test_->seekDoneFlag_ != true) {
return -1;
}
}
return ret;
}
int32_t TestPlayer::GetCurrentTime(int32_t &currentTime)
{
return player->GetCurrentTime(currentTime);
}
int32_t TestPlayer::GetDuration(int32_t &duration)
{
return player->GetDuration(duration);
}
int32_t TestPlayer::SetPlaybackSpeed(PlaybackRateMode mode)
{
return player->SetPlaybackSpeed(mode);
}
int32_t TestPlayer::GetPlaybackSpeed(PlaybackRateMode &mode)
{
return player->GetPlaybackSpeed(mode);
}
sptr<Surface> TestPlayer::GetVideoSurface(WindowConfig sub_config)
{
char surface[256] = "null";
GetParameter("sys.media.test.surface", "null", &surface[0], 256);
mwindow = WindowManager::GetInstance()->CreateWindow(&g_config);
if (mwindow == nullptr) {
MEDIA_ERROR_LOG("Create mwindow failed!!!");
return nullptr;
}
sptr<Surface> videoSurface = nullptr;
if (strcmp(surface, "null") == 0) {
return videoSurface;
}
if (strcmp(surface, "subwindow") == 0) {
InitSubWindow(sub_config);
videoSurface = window->GetSurface();
} else if (strcmp(surface, "window") == 0) {
videoSurface = mwindow->GetSurface();
videoSurface->SetUserData(SURFACE_FORMAT, std::to_string(PIXEL_FMT_RGBA_8888));
std::string format = videoSurface->GetUserData(SURFACE_FORMAT);
MEDIA_INFO_LOG("SetUserData SURFACE_FORMAT = %s", format.c_str());
}
return videoSurface;
}
int32_t TestPlayer::SetVideoSurface(const sptr<Surface> surface)
{
char parameter[256] = "null";
GetParameter("sys.media.test.surface", "null", &parameter[0], 256);
if (strcmp(parameter, "null") == 0) {
MEDIA_INFO_LOG("sys.media.test.surface null");
return 0;
}
return player->SetVideoSurface(surface);
}
bool TestPlayer::IsPlaying()
{
return player->IsPlaying();
}
bool TestPlayer::IsLooping()
{
return player->IsLooping();
}
int32_t TestPlayer::SetLooping(bool loop)
{
return player->SetLooping(loop);
}
int32_t TestPlayer::SetPlayerCallback(const std::shared_ptr<PlayerCallback> &callback)
{
return player->SetPlayerCallback(callback);
}
void TestPlayer::InitSubWindow(WindowConfig sub_config)
{
sptr<SurfaceBuffer> buffer;
BufferRequestConfig requestConfig;
int32_t releaseFence;
mwindow->GetRequestConfig(requestConfig);
(void)mwindow->GetSurface()->RequestBuffer(buffer, releaseFence, requestConfig);
uint32_t buffSize = buffer->GetSize();
void *bufferVirAddr = buffer->GetVirAddr();
(void)memset_s(bufferVirAddr, buffSize, 0, buffSize);
BufferFlushConfig flushConfig = {
.damage = {
.x = 0,
.y = 0,
.w = requestConfig.width,
.h = requestConfig.height,
},
.timestamp = 0,
};
if (mwindow->GetSurface()->FlushBuffer(buffer, -1, flushConfig) != 0) {
MEDIA_ERROR_LOG("FlushBuffer failed");
}
window = WindowManager::GetInstance()->CreateSubWindow(mwindow->GetWindowID(), &sub_config);
ASSERT_NE(nullptr, window);
if (window == nullptr) {
MEDIA_ERROR_LOG("Create window failed!!!");
return;
}
return;
}
TestPlayerCallback::TestPlayerCallback(PlayerSignal *test)
: test_(test)
{
}
TestPlayerCallback::~TestPlayerCallback()
{
}
void TestPlayerCallback::OnError(PlayerErrorType errorType, int32_t errorCode)
{
errorNum++;
errorType_ = errorType;
errorCode_ = errorCode;
MEDIA_INFO_LOG("TestPlayerCallback: OnError errorType is %d, errorCode is %d", errorType_, errorCode_);
}
void TestPlayerCallback::OnInfo(PlayerOnInfoType type, int32_t extra, const Format &InfoBody)
{
switch (type) {
case INFO_TYPE_SEEKDONE:
seekDoneFlag = true;
test_->SetSeekResult(true);
MEDIA_INFO_LOG("TestPlayerCallback: OnSeekDone currentPositon is %d", extra);
if (abs(test_->seekPositon_ - extra) <= DELTA_TIME) {
test_->condVarSeek_.notify_all();
} else {
test_->SetSeekResult(false);
}
break;
case INFO_TYPE_EOS:
MEDIA_INFO_LOG("TestPlayerCallback: OnEndOfStream isLooping is %d", extra);
break;
case INFO_TYPE_STATE_CHANGE:
state_ = static_cast<PlayerStates>(extra);
test_->SetState(state_);
PrintState(state_);
break;
case INFO_TYPE_POSITION_UPDATE:
postion_ = extra;
break;
case INFO_TYPE_MESSAGE:
MEDIA_INFO_LOG("TestPlayerCallback: OnMessage type is %d", extra);
break;
default:
break;
}
}
int TestPlayerCallback::WaitForSeekDone(int32_t currentPositon)
{
int64_t waitTime = 0;
seekDoneFlag = false;
while (seekDoneFlag != true && waitTime < WAITSECOND * 1000) {
usleep(1000);
waitTime += 1;
}
seekDoneFlag = false;
if (waitTime >= WAITSECOND * 1000) {
MEDIA_INFO_LOG("Failed to seek [%d]s ", currentPositon);
return -1;
}
return 0;
}
int TestPlayerCallback::WaitForState(PlayerStates state)
{
int64_t waitTime = 0;
while (state_ != state && waitTime < WAITSECOND * 1000) {
usleep(1000);
waitTime += 1;
}
if (waitTime >= WAITSECOND * 1000) {
MEDIA_INFO_LOG("Failed to wait for state[%d] down", state);
return -1;
}
return 0;
}
void TestPlayerCallback::PrintState(PlayerStates state)
{
switch (state) {
case PLAYER_STATE_ERROR:
MEDIA_INFO_LOG("State: Error");
break;
case PLAYER_IDLE:
MEDIA_INFO_LOG("State: IDLE");
test_->condVarReset_.notify_all();
break;
case PLAYER_INITIALIZED:
MEDIA_INFO_LOG("State: Initialized");
break;
case PLAYER_PREPARING:
MEDIA_INFO_LOG("State: Preparing");
break;
case PLAYER_PREPARED:
MEDIA_INFO_LOG("State: Prepared");
test_->condVarPrepare_.notify_all();
break;
case PLAYER_STARTED:
MEDIA_INFO_LOG("State: Started");
test_->condVarPlay_.notify_all();
break;
case PLAYER_PAUSED:
MEDIA_INFO_LOG("State: Paused");
test_->condVarPause_.notify_all();
break;
case PLAYER_STOPPED:
MEDIA_INFO_LOG("State: Stopped");
test_->condVarStop_.notify_all();
break;
case PLAYER_PLAYBACK_COMPLETE:
MEDIA_INFO_LOG("State: Complete");
break;
default:
MEDIA_INFO_LOG("Invalid state");
break;
}
}
void PlayerSignal::SetState(PlayerStates state)
{
state_ = state;
}
void PlayerSignal::SetSeekResult(bool seekDoneFlag)
{
seekDoneFlag_ = seekDoneFlag;
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PLAYER_API_TEST_H
#define PLAYER_API_TEST_H
#include "Testplayer.h"
namespace OHOS {
namespace Media {
class ActsPlayerAPITest : public testing::Test {
public:
// SetUpTestCase: before all testcasee
static void SetUpTestCase(void)
{
MEDIA_INFO_LOG("ActsPlayerAPITest::SetUpTestCase");
};
// TearDownTestCase: after all testcase
static void TearDownTestCase(void)
{
MEDIA_INFO_LOG("ActsPlayerAPITest::TearDownTestCase");
};
// SetUp
void SetUp(void)
{
MEDIA_INFO_LOG("ActsPlayerAPITest::SetUp");
};
// TearDown
void TearDown(void)
{
MEDIA_INFO_LOG("ActsPlayerAPITest::TearDown");
};
void LocalPlayFunc(const std::string uri, bool isAsync, WindowConfig config = g_config);
};
}
}
#endif
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PLAYER_FUNC_TEST_H
#define PLAYER_FUNC_TEST_H
#include "Testplayer.h"
namespace OHOS {
namespace Media {
class ActsPlayerFuncTest : public testing::Test {
public:
// SetUpTestCase: before all testcasee
static void SetUpTestCase(void)
{
MEDIA_INFO_LOG("ActsPlayerFuncTest::SetUpTestCase");
};
// TearDownTestCase: after all testcase
static void TearDownTestCase(void)
{
MEDIA_INFO_LOG("ActsPlayerFuncTest::TearDownTestCase");
};
// SetUp
void SetUp(void)
{
MEDIA_INFO_LOG("ActsPlayerFuncTest::SetUp");
};
// TearDown
void TearDown(void)
{
MEDIA_INFO_LOG("ActsPlayerFuncTest::TearDown");
};
static void LocalPlayFunc(const std::string uri, bool isAsync, WindowConfig config = g_sub_config);
static void *LocalMulitPlayFunc(void *threadarg);
};
}
}
#endif
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "securec.h"
#include "common.h"
#include "player.h"
#include "mediatest_log.h"
#include "window_manager.h"
#include "surface_type.h"
#include "display_type.h"
namespace PlayerNameSpace {
static const int MAX_THREADS = 16;
static const int32_t PLAYING_TIME = 3;
static const int32_t PAUSED_TIME = 1;
static const int32_t SEEK_TIME_5_SEC = 5000;
static const int32_t SEEK_TIME_2_SEC = 2000;
static const int DELTA_TIME = 1000;
static const int WAITSECOND = 2;
static const int MAXTIME = 20;
static const int RET_OK = 0;
static const int32_t FILE_BEGIN = 0;
std::string GetUri();
}
namespace OHOS {
namespace Media {
static const std::string SURFACE_STRIDE_ALIGNMENT = "SURFACE_STRIDE_ALIGNMENT";
static const std::string SURFACE_FORMAT = "SURFACE_FORMAT";
static WindowConfig g_config = {
1920,
1080,
PIXEL_FMT_RGBA_8888,
0,
0,
WINDOW_TYPE_NORMAL
};
static WindowConfig g_sub_config = {
720,
480,
PIXEL_FMT_YCRCB_420_SP,
0,
0,
WINDOW_TYPE_VIDEO,
};
class PlayerSignal {
public:
PlayerStates state_ = PLAYER_IDLE;
int32_t seekPositon_;
bool seekDoneFlag_;
bool mutexFlag_ = true;
std::mutex mutexSeek_;
std::mutex mutexReset_;
std::mutex mutexPrepare_;
std::mutex mutexPlay_;
std::mutex mutexPause_;
std::mutex mutexStop_;
std::condition_variable condVarSeek_;
std::condition_variable condVarReset_;
std::condition_variable condVarPrepare_;
std::condition_variable condVarPlay_;
std::condition_variable condVarPause_;
std::condition_variable condVarStop_;
void SetState(PlayerStates state);
void SetSeekResult(bool seekDoneFlag);
};
class TestPlayer {
public:
std::shared_ptr<Player> player;
std::unique_ptr<Window> mwindow;
std::unique_ptr<SubWindow> window;
explicit TestPlayer(PlayerSignal *test);
~TestPlayer();
bool CreatePlayer();
int32_t SetSource(const std::string &uri);
int32_t Play();
int32_t Prepare();
int32_t PrepareAsync();
int32_t Pause();
int32_t Stop();
int32_t Reset();
int32_t Release();
int32_t SetVolume(float leftVolume, float rightVolume);
int32_t Seek(int32_t mseconds, PlayerSeekMode mode);
int32_t GetCurrentTime(int32_t &currentTime);
int32_t GetDuration(int32_t &duration);
int32_t SetPlaybackSpeed(PlaybackRateMode mode);
int32_t GetPlaybackSpeed(PlaybackRateMode &mode);
sptr<Surface> GetVideoSurface(WindowConfig g_sub_config);
int32_t SetVideoSurface(sptr<Surface> surface);
bool IsPlaying();
bool IsLooping();
int32_t SetLooping(bool loop);
int32_t SetPlayerCallback(const std::shared_ptr<PlayerCallback> &callback);
private:
void InitSubWindow(WindowConfig sub_config);
PlayerSignal *test_;
};
class TestPlayerCallback : public PlayerCallback {
public:
int errorNum = 0;
PlayerStates state_ = PLAYER_STATE_ERROR;
explicit TestPlayerCallback(PlayerSignal *test);
~TestPlayerCallback();
void OnError(PlayerErrorType errorType, int32_t errorCode);
int WaitForSeekDone(int32_t currentPositon);
void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &InfoBody = {});
int WaitForState(PlayerStates state);
private:
PlayerErrorType errorType_ = PLAYER_ERROR_UNKNOWN;
int32_t errorCode_ = -1;
bool seekDoneFlag = false;
int32_t postion_ = 0;
void PrintState(PlayerStates state);
PlayerSignal *test_;
};
}
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#define MOUNT_147 "/data/147"
#define MOUNT_189 "/data/189"
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ActsPlayerAPITest.h"
#include "player.h"
using namespace std;
using namespace OHOS;
using namespace OHOS::Media;
using namespace testing::ext;
using namespace PlayerNameSpace;
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_0100
* @tc.name : 01.SetSource操作在new之后
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_0100, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
ASSERT_EQ(RET_OK, player->SetSource(uri));
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_0200
* @tc.name : 02.SetSource操作在PrepareAsync之后
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_0200, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
ASSERT_EQ(RET_OK, player->SetSource(uri));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
ASSERT_EQ(RET_OK, player->PrepareAsync());
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_0300
* @tc.name : 03.SetSource操作在Prepare之后
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_0300, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_0400
* @tc.name : 04.SetSource操作在Play之后
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_0400, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_0500
* @tc.name : 05.SetSource操作在Pause之后
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_0500, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_0600
* @tc.name : 06.SetSource操作在Seek之后
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_0600, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_0700
* @tc.name : 07.SetSource操作在Stop之后
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_0700, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_0800
* @tc.name : 08.SetSource操作在Reset之后
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_0800, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
ASSERT_EQ(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_0900
* @tc.name : 09.SetSource操作在SetVideoSurface之后
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_0900, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
EXPECT_NE(RET_OK, player->SetSource(uri));
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_1000
* @tc.name : 10.SetSource操作调用3次
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_1000, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_NE(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetSource_1100
* @tc.name : 11.SetSource操作在每个可进行的操作后都调用一次
* @tc.desc : test SetSource
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetSource_1100, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
EXPECT_NE(RET_OK, player->SetSource(uri));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, player->Reset());
ASSERT_EQ(RET_OK, player->SetSource(uri));
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ActsPlayerAPITest.h"
#include "player.h"
using namespace std;
using namespace OHOS;
using namespace OHOS::Media;
using namespace testing::ext;
using namespace PlayerNameSpace;
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_0100
* @tc.name : 01.Prepare操作在new之后
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_0100, Reliability | SmallTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
EXPECT_NE(RET_OK, player->Prepare());
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_0200
* @tc.name : 02.Prepare操作在PrepareAsync之后
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_0200, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->PrepareAsync());
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_0300
* @tc.name : 03.Prepare操作在SetSource之后
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_0300, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
player->SetVideoSurface(videoSurface);
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_0400
* @tc.name : 04.Prepare操作在Play之后
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_0400, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_0500
* @tc.name : 05.Prepare操作在Pause之后
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_0500, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_0600
* @tc.name : 06.Prepare操作在Seek之后
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_0600, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_0700
* @tc.name : 07.Prepare操作在Stop之后
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_0700, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_0800
* @tc.name : 08.Prepare操作在Reset之后
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_0800, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_0900
* @tc.name : 09.Prepare操作在SetVideoSurface之后
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_0900, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_1000
* @tc.name : 10.Prepare操作调用3次
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_1000, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Prepare_1100
* @tc.name : 11.Prepare操作在每个可进行的操作后都调用一次
* @tc.desc : test Prepare
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Prepare_1100, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ActsPlayerAPITest.h"
#include "player.h"
using namespace std;
using namespace OHOS;
using namespace OHOS::Media;
using namespace testing::ext;
using namespace PlayerNameSpace;
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_0100
* @tc.name : 01.Play操作在new之后
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_0100, Reliability | SmallTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
EXPECT_NE(RET_OK, player->Prepare());
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_0200
* @tc.name : 02.Play操作在PrepareAsync之后
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_0200, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->PrepareAsync());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_0300
* @tc.name : 03.Play操作在Prepare之后
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_0300, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_0400
* @tc.name : 03.Play操作在SetSource之后
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_0400, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
ASSERT_EQ(RET_OK, player->SetSource(uri));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
int32_t time;
EXPECT_NE(RET_OK, player->Play());
EXPECT_FALSE(player->IsPlaying());
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_EQ(2000, time);
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_0500
* @tc.name : 05.Play操作在Pause之后
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_0500, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_0600
* @tc.name : 06.Play操作在Seek之后
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_0600, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_0700
* @tc.name : 07.Play操作在Stop之后
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_0700, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->Play());
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_0800
* @tc.name : 08.Play操作在Reset之后
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_0800, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_0900
* @tc.name : 09.Play操作在SetVideoSurface之后
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_0900, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
EXPECT_NE(RET_OK, player->Play());
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_1000
* @tc.name : 10.Play操作调用3次
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_1000, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Play_1100
* @tc.name : 11.Play操作在每个可进行的操作后都调用一次
* @tc.desc : test Play
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Play_1100, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ActsPlayerAPITest.h"
#include "player.h"
using namespace std;
using namespace OHOS;
using namespace OHOS::Media;
using namespace testing::ext;
using namespace PlayerNameSpace;
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetVolume_0100
* @tc.name : 01.SetVolume 0 0
* @tc.desc : test SetVolume
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetVolume_0100, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
sleep(PLAYING_TIME);
EXPECT_EQ(RET_OK, player->SetVolume(0, 0));
sleep(PLAYING_TIME);
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_SetVolume_0200
* @tc.name : 02.SetVolume 1.0 1.0
* @tc.desc : test SetVolume
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_SetVolume_0200, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
ASSERT_EQ(RET_OK, player->SetSource(uri));
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
sleep(PLAYING_TIME);
EXPECT_EQ(RET_OK, player->SetVolume(1.0, 1.0));
sleep(PLAYING_TIME);
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ActsPlayerAPITest.h"
#include "player.h"
using namespace std;
using namespace OHOS;
using namespace OHOS::Media;
using namespace testing::ext;
using namespace PlayerNameSpace;
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Seek_1500
* @tc.name : 15.GET操作在每个可进行的操作后都调用一次
* @tc.desc : test Seek
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_GetParameter_0100, Reliability | MediumTest | Level2)
{
PlayerSignal testObj;
std::shared_ptr<TestPlayer> player = std::make_shared<TestPlayer>(&testObj);
ASSERT_NE(nullptr, player);
ASSERT_EQ(true, player->CreatePlayer());
std::string uri = GetUri();
int32_t time;
int32_t duration;
int32_t defaultDuration;
EXPECT_NE(RET_OK, player->GetCurrentTime(time));
EXPECT_EQ(0, time);
EXPECT_FALSE(player->IsPlaying());
ASSERT_EQ(RET_OK, player->SetSource(uri));
EXPECT_NE(RET_OK, player->GetCurrentTime(time));
EXPECT_NE(RET_OK, player->GetDuration(duration));
EXPECT_FALSE(player->IsPlaying());
sptr<Surface> videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
EXPECT_NE(RET_OK, player->GetCurrentTime(time));
EXPECT_NE(RET_OK, player->GetDuration(duration));
EXPECT_FALSE(player->IsPlaying());
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
EXPECT_NE(RET_OK, player->GetCurrentTime(time));
EXPECT_NE(RET_OK, player->GetDuration(duration));
EXPECT_FALSE(player->IsPlaying());
// prepare
ASSERT_EQ(RET_OK, player->PrepareAsync());
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_EQ(FILE_BEGIN, time);
EXPECT_EQ(RET_OK, player->GetDuration(defaultDuration));
EXPECT_FALSE(player->IsPlaying());
// play
EXPECT_EQ(RET_OK, player->Play());
EXPECT_TRUE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(FILE_BEGIN, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->GetDuration(duration));
EXPECT_EQ(defaultDuration, duration);
EXPECT_TRUE(player->IsPlaying());
// seek
EXPECT_EQ(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->GetDuration(duration));
EXPECT_EQ(defaultDuration, duration);
// pause
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->GetDuration(duration));
EXPECT_EQ(defaultDuration, duration);
// seek duration
EXPECT_EQ(RET_OK, player->Seek(defaultDuration + 1, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_EQ(defaultDuration, time);
EXPECT_EQ(RET_OK, player->GetDuration(duration));
EXPECT_EQ(defaultDuration, duration);
// stop
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(FILE_BEGIN, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->GetDuration(duration));
EXPECT_EQ(defaultDuration, duration);
EXPECT_FALSE(player->IsPlaying());
// reset
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_NE(RET_OK, player->GetCurrentTime(time));
EXPECT_NE(RET_OK, player->GetDuration(duration));
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
require('../test/fuction/media_player/PlayerLocalTestAudioFUNC.test.js');
require('../test/reliability/media_player/PlayerLocalTestAudioAPI.test.js');
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册