提交 b4cac77a 编写于 作者: O openharmony_ci 提交者: Gitee

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

Merge pull request !440 from tianfenxia/master
......@@ -16,7 +16,9 @@ import("//test/xts/tools/build/suite.gni")
group("multimedia") {
testonly = true
if (is_standard_system) {
deps = [ "audio/audioPlayer:audio_player_js_hap" ]
deps = [
"audio/audio_js_standard/audioPlayer:audio_player_js_hap" ,
"audio/audio_js_standard/audioPlayer_API:audio_player_api_js_hap"]
} else {
deps = [
#"audio/audio_hap_test:MediaAudio_test_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.
*/
/*
* 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.
*/
require('./AudioManager.test.js')
\ No newline at end of file
......@@ -14,5 +14,5 @@ import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("audio_player_js_hap") {
test_hap_name = "AudioPlayerJsTest"
hap_source_path = "hap/entry-debug-rich-signed.hap"
hap_source_path = "hap/AudioPlayer_JS.hap"
}
{
"app": {
"bundleName": "ohos.acts.multimedia.audio.function",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 4
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.multimedia.audio.function",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "ohos.acts.multimedia.audio.function.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
{
"app": {
"bundleName": "ohos.acts.multimedia.audio.function",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 4
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.multimedia.audio.function",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "ohos.acts.multimedia.audio.function.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
/*
* 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 device from '@system.device';
export default {
onCreate() {
console.info('AceApplication onCreate');
},
onDestroy() {
console.info('AceApplication onDestroy');
}
};
/*
* 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 device from '@system.device';
export default {
onCreate() {
console.info('AceApplication onCreate');
},
onDestroy() {
console.info('AceApplication onDestroy');
}
};
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
]
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
]
}
\ 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")
ohos_js_hap_suite("audio_player_api_js_hap") {
test_hap_name = "AudioPlayerApiJsTest"
hap_source_path = "hap/AudioPlayer_Api_JS.hap"
}
{
"description": "Configuration for audio manager Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "21600000",
"package": "ohos.acts.multimedia.audio.function",
"shell-timeout": "21600000"
},
"kits": [
{
"test-file-name": [
"AudioPlayerApiJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.multimedia.audio.function",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 4
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.multimedia.audio.function",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "ohos.acts.multimedia.audio.function.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
/*
* 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 device from '@system.device';
export default {
onCreate() {
console.info('AceApplication onCreate');
},
onDestroy() {
console.info('AceApplication onDestroy');
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
}
}
\ No newline at end of file
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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 file from '@system.file'
import app from '@system.app'
import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index'
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
const reportExtend = new ReportExtend(file)
core.addService('expect', expectExtend)
core.addService('report', reportExtend)
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
require('../../../test/List.test')
core.execute()
},
onReady() {
},
}
\ 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.
*/
require('./PlayerLocalTestAudioAPI.test.js')
\ No newline at end of file
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
]
}
\ 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_Pause_0100
* @tc.name : 01.Pause操作在new之后
* @tc.desc : test Pause
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Pause_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->Pause());
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Pause_0200
* @tc.name : 02.Pause操作在PrepareAsync之后
* @tc.desc : test Pause
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Pause_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->Pause());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Pause_0300
* @tc.name : 03.Pause操作在Prepare之后
* @tc.desc : test Pause
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Pause_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->Pause());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Pause_0500
* @tc.name : 05.Pause操作在Play之后
* @tc.desc : test Pause
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Pause_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->Pause());
EXPECT_FALSE(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_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_Pause_0600
* @tc.name : 06.Pause操作在Seek之后
* @tc.desc : test Pause
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Pause_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->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_Pause_0700
* @tc.name : 07.Pause操作在Stop之后
* @tc.desc : test Pause
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Pause_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_NE(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Pause_0800
* @tc.name : 08.Pause操作在Reset之后
* @tc.desc : test Pause
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Pause_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->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Pause_0900
* @tc.name : 09.Pause操作在SetVideoSurface之后
* @tc.desc : test Pause
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Pause_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));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
EXPECT_NE(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Pause_1000
* @tc.name : 10.Pause操作调用3次
* @tc.desc : test Pause
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Pause_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_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->Pause());
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_Pause_1100
* @tc.name : 10.Pause操作在每个可进行的操作后都调用一次
* @tc.desc : test Pause
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Pause_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));
EXPECT_NE(RET_OK, player->Pause());
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->Pause());
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_NE(RET_OK, player->Pause());
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->GetCurrentTime(time));
EXPECT_NEAR(SEEK_TIME_2_SEC, time, DELTA_TIME);
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->Pause());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_NE(RET_OK, player->Pause());
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_Stop_0100
* @tc.name : 01.Stop操作在new之后
* @tc.desc : test Stop
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Stop_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->Stop());
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Stop_0200
* @tc.name : 02.Stop操作在PrepareAsync之后
* @tc.desc : test Stop
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Stop_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->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(FILE_BEGIN, time, DELTA_TIME);
EXPECT_NE(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->Play());
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_Stop_0300
* @tc.name : 03.Stop操作在Prepare之后
* @tc.desc : test Stop
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Stop_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->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(FILE_BEGIN, time, DELTA_TIME);
EXPECT_NE(RET_OK, player->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_NE(RET_OK, player->Play());
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Stop_0400
* @tc.name : 04.Stop操作在Play之后
* @tc.desc : test Stop
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Stop_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_EQ(RET_OK, player->Stop());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Stop_0500
* @tc.name : 05.Stop操作在Pause之后
* @tc.desc : test Stop
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Stop_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();
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->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Stop_0600
* @tc.name : 06.Stop操作在Seek之后
* @tc.desc : test Stop
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Stop_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->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Stop_0800
* @tc.name : 08.Stop操作在Reset之后
* @tc.desc : test Stop
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Stop_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->Reset());
EXPECT_NE(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Stop_0900
* @tc.name : 09.Stop操作在SetVideoSurface之后
* @tc.desc : test Stop
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Stop_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));
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_EQ(RET_OK, player->Stop());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Stop_1000
* @tc.name : 10.Stop操作调用3次
* @tc.desc : test Stop
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Stop_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_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->Stop());
EXPECT_EQ(RET_OK, player->Stop());
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_Stop_1100
* @tc.name : 11.Stop操作在每个可进行的操作后都调用一次
* @tc.desc : test Stop
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Stop_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));
EXPECT_NE(RET_OK, player->Stop());
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->Stop());
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_NE(RET_OK, player->Play());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_NE(RET_OK, player->Seek(SEEK_TIME_2_SEC, SEEK_PREVIOUS_SYNC));
EXPECT_EQ(RET_OK, player->GetCurrentTime(time));
EXPECT_NEAR(FILE_BEGIN, time, DELTA_TIME);
EXPECT_EQ(RET_OK, player->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_NE(RET_OK, player->Stop());
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_Reset_0100
* @tc.name : 01.Reset操作在new之后
* @tc.desc : test Reset
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Reset_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_EQ(RET_OK, player->Reset());
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Reset_0200
* @tc.name : 02.Reset操作在PrepareAsync之后
* @tc.desc : test Reset
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Reset_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_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Reset_0300
* @tc.name : 03.Reset操作在Prepare之后
* @tc.desc : test Reset
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Reset_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_EQ(RET_OK, player->Reset());
ASSERT_EQ(RET_OK, player->SetSource(uri));
videoSurface = player->GetVideoSurface(g_sub_config);
EXPECT_EQ(RET_OK, player->SetVideoSurface(videoSurface));
testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
ASSERT_EQ(RET_OK, player->Prepare());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Reset_0400
* @tc.name : 04.Reset操作在Play之后
* @tc.desc : test Reset
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Reset_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_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Reset_0500
* @tc.name : 05.Reset操作在Pause之后
* @tc.desc : test Reset
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Reset_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();
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->Pause());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Reset_0600
* @tc.name : 06.Reset操作在Seek之后
* @tc.desc : test Reset
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Reset_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->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Reset_0700
* @tc.name : 07.Reset操作在Stop之后
* @tc.desc : test Reset
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Reset_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->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Reset_0900
* @tc.name : 09.Reset操作在SetVideoSurface之后
* @tc.desc : test Reset
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Reset_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));
std::shared_ptr<TestPlayerCallback> testCallback = std::make_shared<TestPlayerCallback>(&testObj);
EXPECT_EQ(RET_OK, player->SetPlayerCallback(testCallback));
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, testCallback->errorNum);
}
/**
* @tc.number : SUB_MEDIA_PLAYER_API_Reset_1000
* @tc.name : 10.Reset操作调用3次
* @tc.desc : test Reset
*/
HWTEST_F(ActsPlayerAPITest, SUB_MEDIA_PLAYER_API_Reset_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_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->Stop());
EXPECT_FALSE(player->IsPlaying());
EXPECT_EQ(RET_OK, player->Reset());
EXPECT_EQ(RET_OK, player->Reset());
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册