From 6d31676c030e3506ca1b2283d97009d6a7a3709e Mon Sep 17 00:00:00 2001 From: bird_j Date: Sat, 18 Sep 2021 08:04:54 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A4=B4=E6=96=87=E4=BB=B6=E5=88=B7=E6=96=B0?= =?UTF-8?q?=20Signed-off-by:=20bird=5Fj=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/mediatest_log.h | 35 ++++++---- .../player/include/ActsPlayerAPITest.h | 14 ++-- .../player/include/ActsPlayerFuncTest.h | 15 +++-- .../player/include/TestParamsConfig.h | 66 +++++++++++++++++++ .../player/include/Testplayer.h | 32 ++++----- 5 files changed, 120 insertions(+), 42 deletions(-) create mode 100644 multimedia/media/media_cpp_test_standard/player/include/TestParamsConfig.h diff --git a/multimedia/media/media_cpp_test_standard/include/mediatest_log.h b/multimedia/media/media_cpp_test_standard/include/mediatest_log.h index 177567721..17715acdb 100755 --- a/multimedia/media/media_cpp_test_standard/include/mediatest_log.h +++ b/multimedia/media/media_cpp_test_standard/include/mediatest_log.h @@ -13,28 +13,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "media_log.h" +#include "securec.h" -#define MEDIA_DEBUG_LOG(fmt, ...) \ +#define LOGMAXSIZE 200 +#define MEDIA_INFO_LOG(fmt, ...) \ do { \ - printf(fmt, ##__VA_ARGS__); \ - printf("\n"); \ - __MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Debug, fmt, ##__VA_ARGS__); \ -} while (0) \ + char ch[LOGMAXSIZE]; \ + (void)sprintf_s(ch, LOGMAXSIZE, fmt, ##__VA_ARGS__); \ + (void)printf("%s", ch); \ + (void)printf("\n"); \ + __MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Info, "%{public}s", ch); \ +} while (0) -#define MEDIA_INFO_LOG(fmt, ...) \ +#define MEDIA_DEBUG_LOG(fmt, ...) \ do { \ - printf(fmt, ##__VA_ARGS__); \ - printf("\n"); \ - __MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__); \ -} while (0) \ + char ch[LOGMAXSIZE]; \ + (void)sprintf_s(ch, LOGMAXSIZE, fmt, ##__VA_ARGS__); \ + __MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Debug, "%{public}s", ch); \ +} 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) \ + char ch[LOGMAXSIZE]; \ + (void)sprintf_s(ch, LOGMAXSIZE, fmt, ##__VA_ARGS__); \ + (void)printf("%s", ch); \ + (void)printf("\n"); \ + __MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Error, "%{public}s", ch); \ +} while (0) namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "MediaTest"}; diff --git a/multimedia/media/media_cpp_test_standard/player/include/ActsPlayerAPITest.h b/multimedia/media/media_cpp_test_standard/player/include/ActsPlayerAPITest.h index b6b635fb7..b47e9d21d 100755 --- a/multimedia/media/media_cpp_test_standard/player/include/ActsPlayerAPITest.h +++ b/multimedia/media/media_cpp_test_standard/player/include/ActsPlayerAPITest.h @@ -21,25 +21,27 @@ namespace OHOS { namespace Media { class ActsPlayerAPITest : public testing::Test { public: - // SetUpTestCase: before all testcasee + // SetUpTestCase: before all testcases static void SetUpTestCase(void) { - MEDIA_INFO_LOG("ActsPlayerAPITest::SetUpTestCase"); + MEDIA_DEBUG_LOG("ActsPlayerAPITest::SetUpTestCase"); }; - // TearDownTestCase: after all testcase + // TearDownTestCase: after all testcases static void TearDownTestCase(void) { - MEDIA_INFO_LOG("ActsPlayerAPITest::TearDownTestCase"); + MEDIA_DEBUG_LOG("ActsPlayerAPITest::TearDownTestCase"); }; // SetUp void SetUp(void) { - MEDIA_INFO_LOG("ActsPlayerAPITest::SetUp"); + const ::testing::TestInfo * const testInfo = ::testing::UnitTest::GetInstance()->current_test_info(); + MEDIA_DEBUG_LOG("ActsPlayerAPITest::SetUp:%s", testInfo->name()); }; // TearDown void TearDown(void) { - MEDIA_INFO_LOG("ActsPlayerAPITest::TearDown"); + const ::testing::TestInfo * const testInfo = ::testing::UnitTest::GetInstance()->current_test_info(); + MEDIA_DEBUG_LOG("ActsPlayerAPITest::TearDown:%s", testInfo->name()); }; void LocalPlayFunc(const std::string uri, bool isAsync, WindowConfig config = g_config); }; diff --git a/multimedia/media/media_cpp_test_standard/player/include/ActsPlayerFuncTest.h b/multimedia/media/media_cpp_test_standard/player/include/ActsPlayerFuncTest.h index 09925a388..835c71dc9 100755 --- a/multimedia/media/media_cpp_test_standard/player/include/ActsPlayerFuncTest.h +++ b/multimedia/media/media_cpp_test_standard/player/include/ActsPlayerFuncTest.h @@ -21,25 +21,28 @@ namespace OHOS { namespace Media { class ActsPlayerFuncTest : public testing::Test { public: - // SetUpTestCase: before all testcasee + // SetUpTestCase: before all testcases static void SetUpTestCase(void) { - MEDIA_INFO_LOG("ActsPlayerFuncTest::SetUpTestCase"); + MEDIA_DEBUG_LOG("ActsPlayerFuncTest::SetUpTestCase"); + TestPlayerBasic::TestParamsConfig::GetInstance().InitPlayProtocol(); }; - // TearDownTestCase: after all testcase + // TearDownTestCase: after all testcases static void TearDownTestCase(void) { - MEDIA_INFO_LOG("ActsPlayerFuncTest::TearDownTestCase"); + MEDIA_DEBUG_LOG("ActsPlayerFuncTest::TearDownTestCase"); }; // SetUp void SetUp(void) { - MEDIA_INFO_LOG("ActsPlayerFuncTest::SetUp"); + const ::testing::TestInfo * const testInfo = ::testing::UnitTest::GetInstance()->current_test_info(); + MEDIA_DEBUG_LOG("ActsPlayerFuncTest::SetUp:%s", testInfo->name()); }; // TearDown void TearDown(void) { - MEDIA_INFO_LOG("ActsPlayerFuncTest::TearDown"); + const ::testing::TestInfo * const testInfo = ::testing::UnitTest::GetInstance()->current_test_info(); + MEDIA_DEBUG_LOG("ActsPlayerFuncTest::TearDown:%s", testInfo->name()); }; static void LocalPlayFunc(const std::string uri, bool isAsync, WindowConfig config = g_sub_config); static void *LocalMulitPlayFunc(void *threadarg); diff --git a/multimedia/media/media_cpp_test_standard/player/include/TestParamsConfig.h b/multimedia/media/media_cpp_test_standard/player/include/TestParamsConfig.h new file mode 100644 index 000000000..ccd2fea45 --- /dev/null +++ b/multimedia/media/media_cpp_test_standard/player/include/TestParamsConfig.h @@ -0,0 +1,66 @@ +/* + * 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_COMMON_TEST_H +#define PLAYER_COMMON_TEST_H + +#include "gtest/gtest.h" +#include "mediatest_log.h" +#include "player.h" + +namespace { + static const int32_t PLAYING_TIME = 3; + static const int32_t SEEK_TIME_5_SEC = 5000; + static const int32_t SEEK_TIME_2_SEC = 2000; + static const int32_t DELTA_TIME = 1000; + static const int32_t CLOSEST_DELTA_TIME = 300; + static const int32_t WAITSECOND = 2; + static const int32_t RET_OK = 0; + static const int32_t FILE_BEGIN = 0; + static const int32_t PARA_MAX_LEN = 256; + static const int32_t TIME_SEC2MS = 1000; + static const int32_t WAIT_TIME = 1000; + static const OHOS::Media::PlayerSeekMode SEEK_MODE = OHOS::Media::PlayerSeekMode::SEEK_CLOSEST; +} +namespace TestPlayerBasic { +class TestParamsConfig { +public: + static TestParamsConfig& GetInstance() + { + static TestParamsConfig config; + return config; + } + + std::string GetMountPath() const + { + return mountPath_; + } + + void SetMountPath(std::string mountPath) + { + mountPath_ = mountPath; + } + bool CompareTime(int32_t expectTime, int32_t realTme, OHOS::Media::PlayerSeekMode seekMode); + std::string GetUri(); + void InitPlayProtocol(); + +private: + TestParamsConfig(); + ~TestParamsConfig(); + std::string mountPath_ = ""; +}; +} + +#endif \ No newline at end of file diff --git a/multimedia/media/media_cpp_test_standard/player/include/Testplayer.h b/multimedia/media/media_cpp_test_standard/player/include/Testplayer.h index 175835898..92eb84670 100755 --- a/multimedia/media/media_cpp_test_standard/player/include/Testplayer.h +++ b/multimedia/media/media_cpp_test_standard/player/include/Testplayer.h @@ -13,9 +13,11 @@ * limitations under the License. */ +#ifndef PLAYER_TEST_H +#define PLAYER_TEST_H + #include "securec.h" -#include "common.h" -#include "mediatest_log.h" +#include "TestParamsConfig.h" #include "window_manager.h" #include "surface_type.h" #include "display_type.h" @@ -65,13 +67,13 @@ public: }; class TestPlayer { public: - std::shared_ptr player; - std::unique_ptr mwindow; - std::unique_ptr window; - explicit TestPlayer(PlayerSignal *test); - ~TestPlayer(); + std::shared_ptr player_; + sptr window_; + explicit TestPlayer(std::shared_ptr test); + virtual ~TestPlayer(); bool CreatePlayer(); int32_t SetSource(const std::string &uri); + int32_t SetDataSrc(const std::string &uri, bool seekable); int32_t Play(); int32_t Prepare(); int32_t PrepareAsync(); @@ -92,16 +94,14 @@ public: int32_t SetLooping(bool loop); int32_t SetPlayerCallback(const std::shared_ptr &callback); private: - void InitSubWindow(WindowConfig sub_config); - - PlayerSignal *test_; + std::shared_ptr test_; }; class TestPlayerCallback : public PlayerCallback { public: - int errorNum = 0; + int errorNum_ = 0; PlayerStates state_ = PLAYER_STATE_ERROR; - explicit TestPlayerCallback(PlayerSignal *test); - ~TestPlayerCallback(); + explicit TestPlayerCallback(std::shared_ptr test); + virtual ~TestPlayerCallback(); void OnError(PlayerErrorType errorType, int32_t errorCode); int WaitForSeekDone(int32_t currentPositon); void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody = {}); @@ -109,11 +109,11 @@ public: private: PlayerErrorType errorType_ = PLAYER_ERROR_UNKNOWN; int32_t errorCode_ = -1; - bool seekDoneFlag = false; + bool seekDoneFlag_ = false; int32_t postion_ = 0; void PrintState(PlayerStates state); - - PlayerSignal *test_; + std::shared_ptr test_; }; } } +#endif \ No newline at end of file -- GitLab