提交 7187ed4e 编写于 作者: O openharmony_ci 提交者: Gitee

!983 【媒体子系统】解决3518视频播放用例失败

Merge pull request !983 from apperception/OpenHarmony-3.0-LTS
......@@ -11,11 +11,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/subsystem/aafwk/config.gni")
import("//test/xts/tools/lite/build/suite_lite.gni")
hcpptest_suite("ActsMediaPlayerTest") {
suite_name = "acts"
sources = [ "src/ActsMediaPlayerTest.cpp" ]
sources = [ "src/ActsMediaPlayerAudioTest.cpp" ]
if (ohos_kernel_type == "liteos_a" &&
enable_ohos_appexecfwk_feature_ability == true) {
sources += [ "src/ActsMediaPlayerVideoTest.cpp" ]
}
ldflags = [ "-lstdc++" ]
ldflags += [ "-lm" ]
if (ohos_kernel_type == "linux") {
......
......@@ -14,6 +14,9 @@
{
"source": "testcases/multimedia",
"target": "/test_root/multimedia"
},{
"source": "resource/multimedia",
"target": "/test_root/multimedia"
}
]
}
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2020-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
......@@ -13,36 +13,143 @@
* limitations under the License.
*/
#include "ActsMediaPlayerTest.h"
#include <unistd.h>
#include <fcntl.h>
#include "securec.h"
#include <fstream>
#include <iostream>
#include <climits>
#include <unistd.h>
#include <fcntl.h>
#include <sys/prctl.h>
#include "securec.h"
#include "gtest/gtest.h"
#include "source.h"
#include "player.h"
#include "format.h"
#include "thread"
#include "ActsMediaPlayerTest.h"
namespace OHOS {
const string g_avFileName = "1080P_25fps.mp4";
const string g_audioFileName = "Audiochannel_002.m4a";
const int32_t HI_SUCCESS = 0;
const int32_t HI_FAILURE = -1;
using OHOS::Media::Player;
using OHOS::Media::PlayerSeekMode;
using OHOS::Media::Source;
using OHOS::Media::Format;
using OHOS::Media::StreamSource;
using OHOS::Media::StreamCallback;
StreamSourceSample::StreamSourceSample(void)
{
aviableBuffer.clear();
pthread_mutex_init(&m_mutex, nullptr);
}
StreamSourceSample::~StreamSourceSample(void)
{
aviableBuffer.clear();
pthread_mutex_destroy(&m_mutex);
}
void StreamSourceSample::SetStreamCallback(const std::shared_ptr<StreamCallback> &callback)
{
m_callBack = callback;
}
uint8_t *StreamSourceSample::GetBufferAddress(size_t idx)
{
std::shared_ptr<StreamCallback> callback = m_callBack.lock();
if (callback == nullptr) {
return nullptr;
}
return callback->GetBuffer(idx);
}
static void InitSurface()
void StreamSourceSample::QueueBuffer(size_t index, size_t offset, size_t size, int64_t timestampUs, uint32_t flags)
{
OHOS::g_surface->SetUserData("region_position_x", "0");
OHOS::g_surface->SetUserData("region_position_y", "0");
OHOS::g_surface->SetUserData("region_width", "720");
OHOS::g_surface->SetUserData("region_height", "540");
std::shared_ptr<StreamCallback> callback = m_callBack.lock();
if (callback == nullptr) {
return;
}
callback->QueueBuffer(index, offset, size, timestampUs, flags);
}
void StreamSourceSample::OnBufferAvailable(size_t index, size_t offset, size_t size)
{
IdleBuffer buffer;
pthread_mutex_lock(&m_mutex);
buffer.idx = index;
buffer.offset = offset;
buffer.size = size;
aviableBuffer.push_back(buffer);
pthread_mutex_unlock(&m_mutex);
}
int StreamSourceSample::GetAvailableBuffer(IdleBuffer *buffer)
{
pthread_mutex_lock(&m_mutex);
if (aviableBuffer.empty()) {
pthread_mutex_unlock(&m_mutex);
return -1;
}
*buffer = aviableBuffer[0];
aviableBuffer.erase(aviableBuffer.begin());
pthread_mutex_unlock(&m_mutex);
return 0;
}
void *StreamProcess(void *arg)
{
const int gReadLen = 1024;
const int usleepTime = 20000;
const int flags1 = 8;
const int flags2 = 4;
IdleBuffer buffer;
int ret;
uint8_t *data = nullptr;
size_t readLen;
size_t len;
TestSample *sample = (TestSample *)arg;
FILE* pFile = fopen(sample->filePath, "rb");
if (pFile == nullptr) {
return nullptr;
}
prctl(PR_SET_NAME, "StreamProc", 0, 0, 0);
printf("[%s,%d] file:%s\n", __func__, __LINE__, sample->filePath);
while (sample->isThreadRunning) {
ret = sample->streamSample->GetAvailableBuffer(&buffer);
if (ret != 0) {
usleep(usleepTime);
continue;
}
data = sample->streamSample->GetBufferAddress(buffer.idx);
if (data == nullptr) {
printf("[%s, %d] get buffer null", __func__, __LINE__);
break;
}
len = (buffer.size < gReadLen) ? buffer.size : gReadLen;
readLen = fread(data + buffer.offset, 1, len, pFile);
if (readLen <= len && readLen > 0) {
sample->streamSample->QueueBuffer(buffer.idx, buffer.offset, readLen, 0, flags1);
} else {
sample->streamSample->QueueBuffer(buffer.idx, buffer.offset, readLen, 0, flags2);
break;
}
}
fclose(pFile);
printf("[%s,%d]\n", __func__, __LINE__);
return nullptr;
}
void SetSchParam(void)
{
struct sched_param param;
const int priorityNum = 9;
pthread_attr_t attr;
pthread_attr_getschedparam(&attr, &param);
param.sched_priority = priorityNum;
pthread_setschedparam(pthread_self(), SCHED_RR, &param);
}
class PlayerliteTest : public testing::Test {
class ActsMediaPlayerAudioTest : public testing::Test {
protected:
// SetUpTestCase:The preset action of the test suite is executed before the first TestCase
static void SetUpTestCase(void)
......@@ -56,7 +163,6 @@ protected:
virtual void SetUp()
{
g_tagTestSample.adaptr = std::make_shared<Player>();
InitSurface();
}
// TearDown:Execute after each test case
virtual void TearDown()
......@@ -74,7 +180,7 @@ public:
void OnError(int32_t errorType, int32_t errorCode) override;
void OnInfo(int type, int extra) override;
void OnInfo(int32_t type, int32_t extra) override;
void OnVideoSizeChanged(int width, int height) override;
......@@ -109,7 +215,7 @@ void PlayerliteCallback::OnRewindToComplete()
static int32_t FileCheck(const string &argv)
{
if (sizeof(argv.c_str()) < sizeof(g_tagTestSample.filePath) &&
if (strlen(argv.c_str()) < sizeof(g_tagTestSample.filePath) &&
realpath(argv.c_str(), g_tagTestSample.filePath) == nullptr) {
printf("realpath input file failed, errno: %d!\n", errno);
return -1;
......@@ -128,351 +234,238 @@ static int32_t CreateAndSetSource()
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0100
* @tc.name : Video Prepare
* @tc.name : Audio Prepare(),Play() Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_Prepare_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_001, Level1)
{
int32_t ret = FileCheck(g_avFileName);
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
std::string uri(g_tagTestSample.filePath);
Source source(uri);
ret = g_tagTestSample.adaptr->SetSource(source);
string ret1 = source.GetSourceUri();
source.GetSourceType();
ret = g_tagTestSample.adaptr->Prepare();
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(true, flag);
sleep(2);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0200
* @tc.name : Video Prepare
* @tc.name : Audio Play() Pause() Stop() Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_Prepare_test_002, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_002, Level1)
{
int32_t ret = FileCheck(g_avFileName);
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerliteCallback> callBack;
callBack = std::make_shared<PlayerliteCallback>();
g_tagTestSample.adaptr->SetPlayerCallback(callBack);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Stop();
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0300
* @tc.name : Video Play Playback Test
* @tc.name : Audio Play() stop() Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_Play_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_003, Level1)
{
int32_t ret = FileCheck(g_avFileName);
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerliteCallback> callBack;
callBack = std::make_shared<PlayerliteCallback>();
g_tagTestSample.adaptr->SetPlayerCallback(callBack);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
sleep(1);
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(true, flag);
ret = g_tagTestSample.adaptr->Stop();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_FAILURE, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0400
* @tc.name : Video Stop Test
* @tc.name : Audio Prepare() Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_Stop_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_004, Level1)
{
int32_t ret = FileCheck(g_avFileName);
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerliteCallback> callBack;
callBack = std::make_shared<PlayerliteCallback>();
g_tagTestSample.adaptr->SetPlayerCallback(callBack);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerCallback> cb;
g_tagTestSample.adaptr->SetPlayerCallback(cb);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(2);
ret = g_tagTestSample.adaptr->Stop();
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(false, flag);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0500
* @tc.name : Video Stop Test
* @tc.name : Audio Prepare() Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_Stop_test_002, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_005, Level1)
{
int32_t ret = FileCheck(g_avFileName);
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerliteCallback> callBack;
callBack = std::make_shared<PlayerliteCallback>();
g_tagTestSample.adaptr->SetPlayerCallback(callBack);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Stop();
EXPECT_EQ(HI_FAILURE, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0600
* @tc.name : Video Pause Test
* @tc.name : Audio Play(),Stop() Test
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_Pause_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_006, Level1)
{
int32_t ret = FileCheck(g_avFileName);
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerliteCallback> callBack;
callBack = std::make_shared<PlayerliteCallback>();
g_tagTestSample.adaptr->SetPlayerCallback(callBack);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(2);
ret = g_tagTestSample.adaptr->Pause();
ret = g_tagTestSample.adaptr->Stop();
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(false, flag);
g_tagTestSample.adaptr->Release();
}
/* *
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0700
* @tc.name : Video Pause Test
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_Pause_test_002, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_FAILURE, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0800
* @tc.name : Video GetCurrentTime Test
* @tc.name : Audio Play(),Stop(),IsPlay() Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_GetCurrentTime_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_007, Level1)
{
int32_t ret = FileCheck(g_avFileName);
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerliteCallback> callBack;
callBack = std::make_shared<PlayerliteCallback>();
g_tagTestSample.adaptr->SetPlayerCallback(callBack);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(1);
int64_t currentPosition;
ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
ret = g_tagTestSample.adaptr->Stop();
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(false, flag);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0900
* @tc.name : Video GetCurrentTime Test
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0800
* @tc.name : Audio IsPlay() Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_GetCurrentTime_test_002, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_008, Level1)
{
int32_t ret = FileCheck(g_avFileName);
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerliteCallback> callBack;
callBack = std::make_shared<PlayerliteCallback>();
g_tagTestSample.adaptr->SetPlayerCallback(callBack);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
int64_t currentPosition;
ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(1);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(true, flag);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1000
* @tc.name : Video GetDuration Test
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0900
* @tc.name : Audio Play() Pause() Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_GetDuration_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_009, Level1)
{
int32_t ret = FileCheck(g_avFileName);
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerliteCallback> callBack;
callBack = std::make_shared<PlayerliteCallback>();
g_tagTestSample.adaptr->SetPlayerCallback(callBack);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(2);
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Rewind(1, PLAYER_SEEK_NEXT_SYNC);
EXPECT_EQ(HI_SUCCESS, ret);
int64_t currentPosition;
ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1100
* @tc.name : Video GetDuration Test
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_GetDuration_test_002, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
int64_t duration;
ret = g_tagTestSample.adaptr->GetDuration(duration);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1200
* @tc.name : Video GetVideoSurfaceSize Test
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_GetVideoSurfaceSize_test_001, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
int32_t videoWidth;
ret = g_tagTestSample.adaptr->GetVideoWidth(videoWidth);
EXPECT_EQ(HI_SUCCESS, ret);
int32_t videoHeight;
ret = g_tagTestSample.adaptr->GetVideoHeight(videoHeight);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1300
* @tc.name : Video Reset Test
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_Reset_test_001, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(2);
ret = g_tagTestSample.adaptr->Reset();
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1400
* @tc.name : Video Release Test
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_Release_test_001, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(2);
ret = g_tagTestSample.adaptr->Release();
EXPECT_EQ(HI_SUCCESS, ret);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1500
* @tc.name : Audio SetSource Test
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1000
* @tc.name : Audio Pause Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_AudioSetSource_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_010, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerliteCallback> callBack;
callBack = std::make_shared<PlayerliteCallback>();
g_tagTestSample.adaptr->SetPlayerCallback(callBack);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(2);
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_FAILURE, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1600
* @tc.name : Audio Format Play->Pause->Play->Stop Test
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1100
* @tc.name : Audio SetVolume Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_AudioPlay_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_011, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -485,21 +478,18 @@ HWTEST_F(PlayerliteTest, medialite_player_AudioPlay_test_001, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Stop();
ret = g_tagTestSample.adaptr->SetVolume(40, 40);
sleep(10);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1700
* @tc.name : Audio Format Play Test
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1200
* @tc.name : Audio SetVolume Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_Play_test_002, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_012, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -512,19 +502,18 @@ HWTEST_F(PlayerliteTest, medialite_player_Play_test_002, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Stop();
ret = g_tagTestSample.adaptr->SetVolume(0, 0);
sleep(10);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_FAILURE, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1800
* @tc.name : Audio Format Prepare Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1300
* @tc.name : Audio SetVolume Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_audioPrepare_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_013, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -535,15 +524,20 @@ HWTEST_F(PlayerliteTest, medialite_player_audioPrepare_test_001, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVolume(-1, -1);
sleep(10);
EXPECT_EQ(HI_FAILURE, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1900
* @tc.name : Audio Format Prepare Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1400
* @tc.name : Audio SetVolume Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_audioPrepare_test_002, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_014, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -554,17 +548,20 @@ HWTEST_F(PlayerliteTest, medialite_player_audioPrepare_test_002, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVolume(300, 300);
sleep(10);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2000
* @tc.name : Audio Format Stop Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1500
* @tc.name : Audio SetVolume Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_audioStop_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_015, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -577,17 +574,18 @@ HWTEST_F(PlayerliteTest, medialite_player_audioStop_test_001, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Stop();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVolume(300, 301);
sleep(10);
EXPECT_EQ(HI_FAILURE, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2100
* @tc.name : Audio Format Stop Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1600
* @tc.name : Audio SetVolume Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_audioStop_test_002, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_016, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -600,19 +598,18 @@ HWTEST_F(PlayerliteTest, medialite_player_audioStop_test_002, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Stop();
ret = g_tagTestSample.adaptr->SetVolume(50, 100);
sleep(10);
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(false, flag);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2200
* @tc.name : Audio Format Pause Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1700
* @tc.name : Audio Play, GetCurrentTime Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_audioPause_test_002, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_017, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -625,19 +622,19 @@ HWTEST_F(PlayerliteTest, medialite_player_audioPause_test_002, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Pause();
sleep(3);
int64_t currentPosition;
ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2300
* @tc.name : Audio Format SetVolume Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1800
* @tc.name : Audio Play, GetCurrentTime Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_SetVolume_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_018, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -650,18 +647,21 @@ HWTEST_F(PlayerliteTest, medialite_player_SetVolume_test_001, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVolume(40, 40);
sleep(10);
g_tagTestSample.adaptr->Pause();
ret = g_tagTestSample.adaptr->Rewind(0, PLAYER_SEEK_NEXT_SYNC);
EXPECT_EQ(HI_SUCCESS, ret);
int64_t currentPosition;
ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2400
* @tc.name : Audio Format SetVolume Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1900
* @tc.name : Audio Seek Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_SetVolume_test_002, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_019, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -674,18 +674,18 @@ HWTEST_F(PlayerliteTest, medialite_player_SetVolume_test_002, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVolume(0, 0);
sleep(10);
g_tagTestSample.adaptr->Pause();
ret = g_tagTestSample.adaptr->Rewind(4, PLAYER_SEEK_NEXT_SYNC);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2500
* @tc.name : Audio Format SetVolume Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2000
* @tc.name : Audio GetDuration Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_SetVolume_test_003, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_020, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -696,20 +696,18 @@ HWTEST_F(PlayerliteTest, medialite_player_SetVolume_test_003, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
int64_t duration;
ret = g_tagTestSample.adaptr->GetDuration(duration);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVolume(-1, -1);
sleep(10);
EXPECT_EQ(HI_FAILURE, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2600
* @tc.name : Audio Format SetVolume Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2100
* @tc.name : Audio GetDuration Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_SetVolume_test_004, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_021, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -722,18 +720,18 @@ HWTEST_F(PlayerliteTest, medialite_player_SetVolume_test_004, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVolume(300, 300);
sleep(10);
int64_t duration;
ret = g_tagTestSample.adaptr->GetDuration(duration);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2700
* @tc.name : Audio Format SetVolume Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2200
* @tc.name : Audio Reset Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_SetVolume_test_005, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_022, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -746,18 +744,17 @@ HWTEST_F(PlayerliteTest, medialite_player_SetVolume_test_005, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVolume(300, 301);
sleep(10);
EXPECT_EQ(HI_FAILURE, ret);
ret = g_tagTestSample.adaptr->Reset();
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2800
* @tc.name : Audio Format GetCurrentTime Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2300
* @tc.name : Audio Reset Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_audioGetCurrentTime_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_023, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -766,23 +763,17 @@ HWTEST_F(PlayerliteTest, medialite_player_audioGetCurrentTime_test_001, Level1)
g_tagTestSample.adaptr->SetPlayerCallback(callBack);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(3);
int64_t currentPosition;
ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
ret = g_tagTestSample.adaptr->Reset();
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2900
* @tc.name : Audio Format GetCurrentTime Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2400
* @tc.name : Audio EnableSingleLoop() Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_audioGetCurrentTime_test_002, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_024, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -793,23 +784,22 @@ HWTEST_F(PlayerliteTest, medialite_player_audioGetCurrentTime_test_002, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
bool loop = true;
ret = g_tagTestSample.adaptr->EnableSingleLooping(loop);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Pause();
ret = g_tagTestSample.adaptr->Rewind(0, PLAYER_SEEK_NEXT_SYNC);
EXPECT_EQ(HI_SUCCESS, ret);
int64_t currentPosition;
ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(true, flag);
g_tagTestSample.adaptr->Release();
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_3000
* @tc.name : Audio Format Duration Test
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2500
* @tc.name : Audio EnableSingleLoop() Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(PlayerliteTest, medialite_player_audioGetDuration_test_001, Level1)
HWTEST_F(ActsMediaPlayerAudioTest, player_lite_audio_test_025, Level1)
{
int32_t ret = FileCheck(g_audioFileName);
EXPECT_EQ(HI_SUCCESS, ret);
......@@ -820,8 +810,14 @@ HWTEST_F(PlayerliteTest, medialite_player_audioGetDuration_test_001, Level1)
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
int64_t duration;
ret = g_tagTestSample.adaptr->GetDuration(duration);
ret = g_tagTestSample.adaptr->Play();
sleep(1);
EXPECT_EQ(HI_SUCCESS, ret);
bool loop = true;
ret = g_tagTestSample.adaptr->EnableSingleLooping(loop);
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(true, flag);
g_tagTestSample.adaptr->Release();
}
} // OHOS
\ No newline at end of file
} // OHOS
......@@ -15,9 +15,18 @@
#ifndef PLAYER_LITE_TEST_H
#define PLAYER_LITE_TEST_H
#include <sys/prctl.h>
#include <fcntl.h>
#include <climits>
#include "securec.h"
#include "gtest/gtest.h"
#include "source.h"
#include "player.h"
#include "format.h"
#include "fstream"
#include "iostream"
#include "thread"
#include "unistd.h"
namespace OHOS {
using OHOS::Media::Player;
......@@ -35,11 +44,43 @@ using namespace testing::ext;
const int FILE_PATH_LEN = 2048;
class StreamSourceSample;
using TestSample = struct TagTestSample {
std::shared_ptr<Player> adaptr;
pthread_t process;
pthread_mutex_t mutex;
int32_t isThreadRunning;
int32_t sourceType;
char filePath[FILE_PATH_LEN];
std::shared_ptr<StreamSourceSample> streamSample;
};
using IdleBuffer = struct TagIdleBuffer {
size_t idx;
size_t offset;
size_t size;
};
class StreamSourceSample : public StreamSource {
public:
StreamSourceSample(void);
~StreamSourceSample(void);
void OnBufferAvailable(size_t index, size_t offset, size_t size);
void SetStreamCallback(const std::shared_ptr<StreamCallback> &callback);
uint8_t *GetBufferAddress(size_t idx);
void QueueBuffer(size_t index, size_t offset, size_t size, int64_t timestampUs, uint32_t flags);
int GetAvailableBuffer(IdleBuffer *buffer);
std::weak_ptr<StreamCallback> m_callBack;
pthread_mutex_t m_mutex;
private:
std::vector<IdleBuffer> aviableBuffer;
};
void *StreamProcess(const void *arg);
void SetSchParam(void);
const int32_t HI_SUCCESS = 0;
const int32_t HI_FAILURE = -1;
static TagTestSample g_tagTestSample;
static Surface *g_surface = Surface::CreateSurface();
} // namespace OHOS
......
/*
* Copyright (C) 2020-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 "ActsMediaPlayerTest.h"
namespace OHOS {
const string g_avFileName = "1080P_25fps.mp4";
static void InitSurface()
{
OHOS::g_surface->SetUserData("region_position_x", "0");
OHOS::g_surface->SetUserData("region_position_y", "0");
OHOS::g_surface->SetUserData("region_width", "720");
OHOS::g_surface->SetUserData("region_height", "540");
}
class ActsMediaPlayerVideoTest : public testing::Test {
protected:
// SetUpTestCase:The preset action of the test suite is executed before the first TestCase
static void SetUpTestCase(void)
{
}
// TearDownTestCase:The test suite cleanup action is executed after the last TestCase
static void TearDownTestCase(void)
{
}
// SetUp:Execute before each test case
virtual void SetUp()
{
g_tagTestSample.adaptr = std::make_shared<Player>();
InitSurface();
}
// TearDown:Execute after each test case
virtual void TearDown()
{
}
};
static int32_t FileCheck(const string &argv)
{
const char *ptr = argv.c_str();
if (strlen(ptr) < FILE_PATH_LEN &&
realpath(argv.c_str(), g_tagTestSample.filePath) == nullptr) {
printf("realpath input file failed, errno: %d!\n", errno);
return -1;
}
return 0;
}
static int32_t CreateAndSetSource()
{
std::string uri(g_tagTestSample.filePath);
Source source(uri);
int32_t ret = g_tagTestSample.adaptr->SetSource(source);
string ret1 = source.GetSourceUri();
return ret;
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0100
* @tc.name : Video Prepare Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_001, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(true, flag);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0200
* @tc.name : Video Prepare Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_002, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0300
* @tc.name : Video Play Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_003, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
sleep(1);
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(true, flag);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0400
* @tc.name : Video Stop Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_004, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
std::shared_ptr<PlayerCallback> cb;
g_tagTestSample.adaptr->SetPlayerCallback(cb);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(2);
ret = g_tagTestSample.adaptr->Stop();
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(false, flag);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0500
* @tc.name : Video Stop Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_005, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Stop();
EXPECT_EQ(HI_FAILURE, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0600
* @tc.name : Video Pause Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_006, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(2);
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(false, flag);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0700
* @tc.name : Video Pause Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_007, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_FAILURE, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0800
* @tc.name : Video GetCurrentTime Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_008, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(1);
int64_t currentPosition;
ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_0900
* @tc.name : Video GetCurrentTime Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_009, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
int64_t currentPosition;
ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(1);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(true, flag);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1000
* @tc.name : Video GetDuration Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_010, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(1);
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Rewind(1, PLAYER_SEEK_NEXT_SYNC);
EXPECT_EQ(HI_SUCCESS, ret);
int64_t currentPosition;
ret = g_tagTestSample.adaptr->GetCurrentTime(currentPosition);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1100
* @tc.name : Video Rewind Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_011, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(1);
ret = g_tagTestSample.adaptr->Pause();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Rewind(4, PLAYER_SEEK_NEXT_SYNC);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1200
* @tc.name : Video GetDuration Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_012, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
int64_t duration;
ret = g_tagTestSample.adaptr->GetDuration(duration);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1300
* @tc.name : Video GetVideoSurfaceSize Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_013, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
int32_t videoWidth;
ret = g_tagTestSample.adaptr->GetVideoWidth(videoWidth);
EXPECT_EQ(HI_SUCCESS, ret);
int32_t videoHeight;
ret = g_tagTestSample.adaptr->GetVideoHeight(videoHeight);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1400
* @tc.name : Video GetVideoSurfaceSize Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_014, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
int32_t videoWidth;
ret = g_tagTestSample.adaptr->GetVideoWidth(videoWidth);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1500
* @tc.name : Video GetVideoSurfaceSize Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_015, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
int32_t videoHeight;
ret = g_tagTestSample.adaptr->GetVideoHeight(videoHeight);
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1600
* @tc.name : Video Reset Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_016, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(2);
ret = g_tagTestSample.adaptr->Reset();
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1700
* @tc.name : Video Reset Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_017, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Reset();
EXPECT_EQ(HI_SUCCESS, ret);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1800
* @tc.name : Video Release Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_018, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(2);
ret = g_tagTestSample.adaptr->Release();
EXPECT_EQ(HI_SUCCESS, ret);
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_1900
* @tc.name : Video EnableSingleLooping Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_019, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
bool loop = true;
ret = g_tagTestSample.adaptr->EnableSingleLooping(loop);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
sleep(1);
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(true, flag);
g_tagTestSample.adaptr->Release();
sleep(1);
}
/* *
* @tc.number : SUB_MEDIA_PLAYER_PLAY_2000
* @tc.name : Video EnableSingleLooping Test.
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaPlayerVideoTest, player_lite_video_test_020, Level1)
{
int32_t ret = FileCheck(g_avFileName);
EXPECT_EQ(HI_SUCCESS, ret);
ret = CreateAndSetSource();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Prepare();
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->SetVideoSurface(g_surface);
EXPECT_EQ(HI_SUCCESS, ret);
ret = g_tagTestSample.adaptr->Play();
sleep(1);
EXPECT_EQ(HI_SUCCESS, ret);
bool loop = true;
ret = g_tagTestSample.adaptr->EnableSingleLooping(loop);
EXPECT_EQ(HI_SUCCESS, ret);
bool flag = g_tagTestSample.adaptr->IsPlaying();
EXPECT_EQ(true, flag);
g_tagTestSample.adaptr->Release();
}
} // OHOS
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册