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

!1247 media test case 同步刷新

Merge pull request !1247 from NOBUGGERS/nobuggers-master-patch-98871
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -14,14 +13,17 @@ ...@@ -14,14 +13,17 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef MEDIA_TEST_LOG_H
#define MEDIA_TEST_LOG_H
#include "media_log.h" #include "media_log.h"
#include "securec.h" #include "securec.h"
#define LOGMAXSIZE 200 #define LOG_MAX_SIZE 200
#define MEDIA_INFO_LOG(fmt, ...) \ #define MEDIA_INFO_LOG(fmt, ...) \
do { \ do { \
char ch[LOGMAXSIZE]; \ char ch[LOG_MAX_SIZE]; \
(void)sprintf_s(ch, LOGMAXSIZE, fmt, ##__VA_ARGS__); \ (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__); \
(void)printf("%s", ch); \ (void)printf("%s", ch); \
(void)printf("\n"); \ (void)printf("\n"); \
__MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Info, "%{public}s", ch); \ __MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Info, "%{public}s", ch); \
...@@ -29,15 +31,15 @@ do { \ ...@@ -29,15 +31,15 @@ do { \
#define MEDIA_DEBUG_LOG(fmt, ...) \ #define MEDIA_DEBUG_LOG(fmt, ...) \
do { \ do { \
char ch[LOGMAXSIZE]; \ char ch[LOG_MAX_SIZE]; \
(void)sprintf_s(ch, LOGMAXSIZE, fmt, ##__VA_ARGS__); \ (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__); \
__MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Debug, "%{public}s", ch); \ __MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Debug, "%{public}s", ch); \
} while (0) } while (0)
#define MEDIA_ERROR_LOG(fmt, ...) \ #define MEDIA_ERROR_LOG(fmt, ...) \
do { \ do { \
char ch[LOGMAXSIZE]; \ char ch[LOG_MAX_SIZE]; \
(void)sprintf_s(ch, LOGMAXSIZE, fmt, ##__VA_ARGS__); \ (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__); \
(void)printf("%s", ch); \ (void)printf("%s", ch); \
(void)printf("\n"); \ (void)printf("\n"); \
__MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Error, "%{public}s", ch); \ __MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Error, "%{public}s", ch); \
...@@ -56,3 +58,4 @@ namespace MediaTest { ...@@ -56,3 +58,4 @@ namespace MediaTest {
const int HEIGHT = 720; const int HEIGHT = 720;
const int WIDTH = 1280; const int WIDTH = 1280;
} }
#endif
...@@ -25,6 +25,7 @@ public: ...@@ -25,6 +25,7 @@ public:
static void SetUpTestCase(void) static void SetUpTestCase(void)
{ {
MEDIA_DEBUG_LOG("ActsPlayerAPITest::SetUpTestCase"); MEDIA_DEBUG_LOG("ActsPlayerAPITest::SetUpTestCase");
TestPlayerBasic::TestParamsConfig::GetInstance().InitMountPath();
}; };
// TearDownTestCase: after all testcases // TearDownTestCase: after all testcases
static void TearDownTestCase(void) static void TearDownTestCase(void)
......
...@@ -25,7 +25,7 @@ public: ...@@ -25,7 +25,7 @@ public:
static void SetUpTestCase(void) static void SetUpTestCase(void)
{ {
MEDIA_DEBUG_LOG("ActsPlayerFuncTest::SetUpTestCase"); MEDIA_DEBUG_LOG("ActsPlayerFuncTest::SetUpTestCase");
TestPlayerBasic::TestParamsConfig::GetInstance().InitPlayProtocol(); TestPlayerBasic::TestParamsConfig::GetInstance().InitMountPath();
}; };
// TearDownTestCase: after all testcases // TearDownTestCase: after all testcases
static void TearDownTestCase(void) static void TearDownTestCase(void)
...@@ -35,6 +35,7 @@ public: ...@@ -35,6 +35,7 @@ public:
// SetUp // SetUp
void SetUp(void) void SetUp(void)
{ {
uri_ = TestPlayerBasic::TestParamsConfig::GetInstance().GetUri();
const ::testing::TestInfo * const testInfo = ::testing::UnitTest::GetInstance()->current_test_info(); const ::testing::TestInfo * const testInfo = ::testing::UnitTest::GetInstance()->current_test_info();
MEDIA_DEBUG_LOG("ActsPlayerFuncTest::SetUp:%s", testInfo->name()); MEDIA_DEBUG_LOG("ActsPlayerFuncTest::SetUp:%s", testInfo->name());
}; };
...@@ -45,6 +46,10 @@ public: ...@@ -45,6 +46,10 @@ public:
MEDIA_DEBUG_LOG("ActsPlayerFuncTest::TearDown:%s", testInfo->name()); MEDIA_DEBUG_LOG("ActsPlayerFuncTest::TearDown:%s", testInfo->name());
}; };
static void LocalPlayFunc(const std::string uri, bool isAsync, WindowConfig config = g_sub_config); static void LocalPlayFunc(const std::string uri, bool isAsync, WindowConfig config = g_sub_config);
void PreparePlayEnv(std::shared_ptr<TestPlayer> &player);
std::string uri_ = "";
std::shared_ptr<TestPlayerCallback> testCallback_;
std::shared_ptr<PlayerSignal> testObj_;
}; };
} }
} }
......
...@@ -37,6 +37,7 @@ namespace { ...@@ -37,6 +37,7 @@ namespace {
namespace TestPlayerBasic { namespace TestPlayerBasic {
class TestParamsConfig { class TestParamsConfig {
public: public:
DISALLOW_COPY_AND_MOVE(TestParamsConfig);
static TestParamsConfig &GetInstance() static TestParamsConfig &GetInstance()
{ {
static TestParamsConfig config; static TestParamsConfig config;
...@@ -54,7 +55,7 @@ public: ...@@ -54,7 +55,7 @@ public:
} }
bool CompareTime(int32_t expectTime, int32_t realTme, OHOS::Media::PlayerSeekMode seekMode); bool CompareTime(int32_t expectTime, int32_t realTme, OHOS::Media::PlayerSeekMode seekMode);
std::string GetUri(); std::string GetUri();
void InitPlayProtocol(); void InitMountPath();
private: private:
TestParamsConfig(); TestParamsConfig();
......
...@@ -46,7 +46,7 @@ static WindowConfig g_sub_config = { ...@@ -46,7 +46,7 @@ static WindowConfig g_sub_config = {
class PlayerSignal { class PlayerSignal {
public: public:
PlayerStates state_ = PLAYER_IDLE; PlayerStates state_ = PLAYER_IDLE;
int32_t seekPositon_; int32_t seekPosition_;
bool seekDoneFlag_; bool seekDoneFlag_;
bool mutexFlag_ = true; bool mutexFlag_ = true;
std::mutex mutexSeek_; std::mutex mutexSeek_;
...@@ -71,6 +71,7 @@ public: ...@@ -71,6 +71,7 @@ public:
sptr<Window> window_ = nullptr; sptr<Window> window_ = nullptr;
explicit TestPlayer(std::shared_ptr<PlayerSignal> test); explicit TestPlayer(std::shared_ptr<PlayerSignal> test);
virtual ~TestPlayer(); virtual ~TestPlayer();
DISALLOW_COPY_AND_MOVE(TestPlayer);
bool CreatePlayer(); bool CreatePlayer();
int32_t SetSource(const std::string &uri); int32_t SetSource(const std::string &uri);
int32_t SetDataSrc(const std::string &uri, bool seekable); int32_t SetDataSrc(const std::string &uri, bool seekable);
...@@ -102,8 +103,9 @@ public: ...@@ -102,8 +103,9 @@ public:
PlayerStates state_ = PLAYER_STATE_ERROR; PlayerStates state_ = PLAYER_STATE_ERROR;
explicit TestPlayerCallback(std::shared_ptr<PlayerSignal> test); explicit TestPlayerCallback(std::shared_ptr<PlayerSignal> test);
virtual ~TestPlayerCallback(); virtual ~TestPlayerCallback();
DISALLOW_COPY_AND_MOVE(TestPlayerCallback);
void OnError(PlayerErrorType errorType, int32_t errorCode); void OnError(PlayerErrorType errorType, int32_t errorCode);
int WaitForSeekDone(int32_t currentPositon); int WaitForSeekDone(int32_t currentPosition);
void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody = {}); void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody = {});
int WaitForState(PlayerStates state); int WaitForState(PlayerStates state);
private: private:
......
...@@ -35,28 +35,43 @@ std::string TestParamsConfig::GetUri() ...@@ -35,28 +35,43 @@ std::string TestParamsConfig::GetUri()
MEDIA_INFO_LOG("PATH : %s", path); MEDIA_INFO_LOG("PATH : %s", path);
return path; return path;
} }
void TestParamsConfig::InitPlayProtocol() void TestParamsConfig::InitMountPath()
{ {
MEDIA_INFO_LOG("%s", __FUNCTION__); MEDIA_INFO_LOG("%s", __FUNCTION__);
char protocol[PARA_MAX_LEN] = "local"; char mountPath[PARA_MAX_LEN] = "null";
GetParameter("sys.media.test.play.protocol", "local", &protocol[0], PARA_MAX_LEN); GetParameter("sys.media.test.mount.path", "null", &mountPath[0], PARA_MAX_LEN);
if (strcmp(protocol, "local") == 0) { if (strcmp(mountPath, "null") != 0) {
TestPlayerBasic::TestParamsConfig::GetInstance().SetMountPath("file://data/media/"); TestPlayerBasic::TestParamsConfig::GetInstance().SetMountPath(mountPath);
} else {
MEDIA_INFO_LOG("MOUNT_PATH %s", TestPlayerBasic::TestParamsConfig::GetInstance().GetMountPath().c_str()); TestPlayerBasic::TestParamsConfig::GetInstance().SetMountPath("file:///data/media/");
} }
MEDIA_INFO_LOG("MOUNT_PATH %s", TestPlayerBasic::TestParamsConfig::GetInstance().GetMountPath().c_str());
} }
bool TestParamsConfig::CompareTime(int32_t expectTime, int32_t realTime, OHOS::Media::PlayerSeekMode seekMode) bool TestParamsConfig::CompareTime(int32_t expectTime, int32_t realTime, OHOS::Media::PlayerSeekMode seekMode)
{ {
MEDIA_INFO_LOG("CompareTime: expectTime %d, realTime %d", expectTime, realTime); MEDIA_INFO_LOG("CompareTime: expectTime %d, realTime %d", expectTime, realTime);
if (seekMode == OHOS::Media::PlayerSeekMode::SEEK_CLOSEST) { if (seekMode == PlayerSeekMode::SEEK_CLOSEST) {
if (std::abs(expectTime - realTime) < CLOSEST_DELTA_TIME) { if (std::abs(expectTime - realTime) < CLOSEST_DELTA_TIME) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
if (seekMode == PlayerSeekMode::SEEK_NEXT_SYNC) {
if (realTime - expectTime < DELTA_TIME && realTime - expectTime >= 0) {
return true;
} else {
return false;
}
}
if (seekMode == PlayerSeekMode::SEEK_PREVIOUS_SYNC) {
if (expectTime - realTime < DELTA_TIME && expectTime - realTime > -CLOSEST_DELTA_TIME) {
return true;
} else {
return false;
}
}
if (std::abs(expectTime - realTime) < DELTA_TIME) { if (std::abs(expectTime - realTime) < DELTA_TIME) {
return true; return true;
} }
......
...@@ -146,7 +146,7 @@ int32_t TestPlayer::Seek(int32_t mseconds, PlayerSeekMode mode) ...@@ -146,7 +146,7 @@ int32_t TestPlayer::Seek(int32_t mseconds, PlayerSeekMode mode)
{ {
MEDIA_DEBUG_LOG("%s", __FUNCTION__); MEDIA_DEBUG_LOG("%s", __FUNCTION__);
test_->seekDoneFlag_ = false; test_->seekDoneFlag_ = false;
test_->seekPositon_ = mseconds; test_->seekPosition_ = mseconds;
int32_t ret = player_->Seek(mseconds, mode); int32_t ret = player_->Seek(mseconds, mode);
if (ret == RET_OK && test_->mutexFlag_ == true && test_->seekDoneFlag_ == false) { if (ret == RET_OK && test_->mutexFlag_ == true && test_->seekDoneFlag_ == false) {
std::unique_lock<std::mutex> lockSeek(test_->mutexSeek_); std::unique_lock<std::mutex> lockSeek(test_->mutexSeek_);
...@@ -274,8 +274,8 @@ void TestPlayerCallback::OnInfo(PlayerOnInfoType type, int32_t extra, const Form ...@@ -274,8 +274,8 @@ void TestPlayerCallback::OnInfo(PlayerOnInfoType type, int32_t extra, const Form
case INFO_TYPE_SEEKDONE: case INFO_TYPE_SEEKDONE:
seekDoneFlag_ = true; seekDoneFlag_ = true;
test_->SetSeekResult(true); test_->SetSeekResult(true);
MEDIA_INFO_LOG("TestPlayerCallback: OnSeekDone currentPositon is %d", extra); MEDIA_INFO_LOG("TestPlayerCallback: OnSeekDone currentPosition is %d", extra);
if (abs(test_->seekPositon_ - extra) <= DELTA_TIME) { if (abs(test_->seekPosition_ - extra) <= DELTA_TIME) {
test_->condVarSeek_.notify_all(); test_->condVarSeek_.notify_all();
} else { } else {
test_->SetSeekResult(false); test_->SetSeekResult(false);
...@@ -299,17 +299,20 @@ void TestPlayerCallback::OnInfo(PlayerOnInfoType type, int32_t extra, const Form ...@@ -299,17 +299,20 @@ void TestPlayerCallback::OnInfo(PlayerOnInfoType type, int32_t extra, const Form
} }
} }
int TestPlayerCallback::WaitForSeekDone(int32_t currentPositon) int TestPlayerCallback::WaitForSeekDone(int32_t currentPosition)
{ {
int64_t waitTime = 0; auto start = std::chrono::system_clock::now();
auto end = std::chrono::system_clock::now();
uint64_t waitTime = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
seekDoneFlag_ = false; seekDoneFlag_ = false;
while (seekDoneFlag_ != true && waitTime < WAITSECOND * TIME_SEC2MS) { while (seekDoneFlag_ != true && waitTime < WAITSECOND * TIME_SEC2MS) {
(void)usleep(WAIT_TIME); (void)usleep(WAIT_TIME);
waitTime += 1; end = std::chrono::system_clock::now();
waitTime = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
} }
seekDoneFlag_ = false; seekDoneFlag_ = false;
if (waitTime >= WAITSECOND * TIME_SEC2MS) { if (waitTime >= WAITSECOND * TIME_SEC2MS) {
MEDIA_ERROR_LOG("Failed to seek [%d]s ", currentPositon); MEDIA_ERROR_LOG("Failed to seek [%d] ms ", currentPosition);
return -1; return -1;
} }
return 0; return 0;
...@@ -317,12 +320,16 @@ int TestPlayerCallback::WaitForSeekDone(int32_t currentPositon) ...@@ -317,12 +320,16 @@ int TestPlayerCallback::WaitForSeekDone(int32_t currentPositon)
int TestPlayerCallback::WaitForState(PlayerStates state) int TestPlayerCallback::WaitForState(PlayerStates state)
{ {
int64_t waitTime = 0; auto start = std::chrono::system_clock::now();
while (state_ != state && waitTime < WAITSECOND * TIME_SEC2MS) { auto end = std::chrono::system_clock::now();
uint64_t waitTime = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
const uint64_t waitTimeMax = 4000;
while (state_ != state && waitTime < waitTimeMax) {
(void)usleep(WAIT_TIME); (void)usleep(WAIT_TIME);
waitTime += 1; end = std::chrono::system_clock::now();
waitTime = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
} }
if (waitTime >= WAITSECOND * TIME_SEC2MS) { if (waitTime >= waitTimeMax) {
MEDIA_ERROR_LOG("Failed to wait for state[%d] down", state); MEDIA_ERROR_LOG("Failed to wait for state[%d] down", state);
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册