From b8656bbe52b6852dc97f658962a8d5c0a27739eb Mon Sep 17 00:00:00 2001 From: chenzhenyu27 Date: Tue, 22 Jul 2025 10:45:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E7=85=A7=E7=89=87=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=8E=A7=E5=88=B6=E7=9A=84tdd=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenzhenyu27 --- .../movingphoto/movingphoto_test_ng.cpp | 195 ++++++++++++++++++ 1 file changed, 195 insertions(+) diff --git a/test/unittest/core/pattern/movingphoto/movingphoto_test_ng.cpp b/test/unittest/core/pattern/movingphoto/movingphoto_test_ng.cpp index d809e6cef82..426315d8c91 100644 --- a/test/unittest/core/pattern/movingphoto/movingphoto_test_ng.cpp +++ b/test/unittest/core/pattern/movingphoto/movingphoto_test_ng.cpp @@ -225,6 +225,8 @@ HWTEST_F(MovingphotoTestNg, MovingPhotoEventTest003, TestSize.Level1) * @tc.steps: step2. set movingphoto event * @tc.expected: step2. get movingphoto event right */ + auto onPreparedEvent = []() {}; + movingphoto.SetOnPrepared(onPreparedEvent); auto onStartEvent = []() {}; movingphoto.SetOnStart(onStartEvent); auto onFinishEvent = []() {}; @@ -239,6 +241,9 @@ HWTEST_F(MovingphotoTestNg, MovingPhotoEventTest003, TestSize.Level1) auto movingPhotoEventHub = frameNode->GetOrCreateEventHub(); EXPECT_TRUE(movingPhotoEventHub != nullptr); + movingPhotoEventHub->FirePreparedEvent(); + auto onPrepared_ = movingPhotoEventHub->GetOnPrepared(); + EXPECT_TRUE(onPrepared_ != nullptr); movingPhotoEventHub->FireStartEvent(); auto onStart_ = movingPhotoEventHub->GetOnStart(); EXPECT_TRUE(onStart_ != nullptr); @@ -1242,4 +1247,194 @@ HWTEST_F(MovingphotoTestNg, MovingPhotoPatternTest025, TestSize.Level1) pattern->SetWaterMask(true); EXPECT_EQ(pattern->GetWaterMask(), true); } + +/** + * @tc.name: MovingPhotoPatternTest026 + * @tc.desc: Test MovingPhotoPattern PauseVideo. + * @tc.type: FUNC + */ +HWTEST_F(MovingphotoTestNg, MovingPhotoPatternTest026, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create MovingPhoto and get MovingPhotoPattern. + */ + MovingPhotoModelNG movingphoto; + movingphoto.Create(AceType::MakeRefPtr()); + auto movingphotoNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(movingphotoNode, nullptr); + auto movingphotoPattern = movingphotoNode->GetPattern(); + ASSERT_NE(movingphotoPattern, nullptr); + + /** + * @tc.steps: step2. Call PauseVideo. + * @tc.expected: MovingPhoto pause. + */ + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->mediaPlayer_)), IsMediaPlayerValid()) + .WillRepeatedly(Return(true)); + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->renderSurface_)), IsSurfaceValid()) + .WillRepeatedly(Return(true)); + movingphotoPattern->isStopAnimation_ = false; + movingphotoPattern->isPrepared_ = false; + movingphotoPattern->currentPlayStatus_= PlaybackStatus::NONE; + movingphotoPattern->PauseVideo(); + ASSERT_FALSE(movingphotoPattern->isStopAnimation_); + movingphotoPattern->isPrepared_ = true; + movingphotoPattern->autoAndRepeatLevel_ = PlaybackMode::REPEAT; + movingphotoPattern->currentPlayStatus_= PlaybackStatus::STARTED; + movingphotoPattern->PauseVideo(); + ASSERT_FALSE(movingphotoPattern->isStopAnimation_); + movingphotoPattern->autoAndRepeatLevel_ = PlaybackMode::NONE; + movingphotoPattern->PauseVideo(); + ASSERT_TRUE(movingphotoPattern->isStopAnimation_); +} + +/** + * @tc.name: MovingPhotoPatternTest027 + * @tc.desc: Test MovingPhotoPattern ResetVideo. + * @tc.type: FUNC + */ +HWTEST_F(MovingphotoTestNg, MovingPhotoPatternTest027, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create MovingPhoto and get MovingPhotoPattern. + */ + MovingPhotoModelNG movingphoto; + movingphoto.Create(AceType::MakeRefPtr()); + auto movingphotoNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(movingphotoNode, nullptr); + auto movingphotoPattern = movingphotoNode->GetPattern(); + ASSERT_NE(movingphotoPattern, nullptr); + + /** + * @tc.steps: step2. Call ResetVideo. + * @tc.expected: MovingPhoto reset. + */ + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->mediaPlayer_)), IsMediaPlayerValid()) + .WillRepeatedly(Return(true)); + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->renderSurface_)), IsSurfaceValid()) + .WillRepeatedly(Return(true)); + movingphotoPattern->ResetVideo(); + ASSERT_EQ(movingphotoPattern->historyAutoAndRepeatLevel_, PlaybackMode::NONE); + ASSERT_EQ(movingphotoPattern->autoAndRepeatLevel_, PlaybackMode::NONE); + ASSERT_FALSE(movingphotoPattern->isSetAutoPlayPeriod_); +} + +/** + * @tc.name: MovingPhotoPatternTest028 + * @tc.desc: Test MovingPhotoPattern RestartVideo. + * @tc.type: FUNC + */ +HWTEST_F(MovingphotoTestNg, MovingPhotoPatternTest028, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create MovingPhoto and get MovingPhotoPattern. + */ + MovingPhotoModelNG movingphoto; + movingphoto.Create(AceType::MakeRefPtr()); + auto movingphotoNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(movingphotoNode, nullptr); + auto movingphotoPattern = movingphotoNode->GetPattern(); + ASSERT_NE(movingphotoPattern, nullptr); + + /** + * @tc.steps: step2. Call RestartVideo. + * @tc.expected: MovingPhoto restart. + */ + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->mediaPlayer_)), IsMediaPlayerValid()) + .WillRepeatedly(Return(true)); + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->renderSurface_)), IsSurfaceValid()) + .WillRepeatedly(Return(true)); + movingphotoPattern->isPlayByController_ = false; + movingphotoPattern->RestartVideo(); + ASSERT_TRUE(movingphotoPattern->GetPlayByController()); +} + +/** + * @tc.name: MovingPhotoPatternTest029 + * @tc.desc: Test MovingPhotoPattern SetEnableTransition. + * @tc.type: FUNC + */ +HWTEST_F(MovingphotoTestNg, MovingPhotoPatternTest029, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create MovingPhoto and get MovingPhotoPattern. + */ + MovingPhotoModelNG movingphoto; + movingphoto.Create(AceType::MakeRefPtr()); + auto movingphotoNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(movingphotoNode, nullptr); + auto movingphotoPattern = movingphotoNode->GetPattern(); + ASSERT_NE(movingphotoPattern, nullptr); + + /** + * @tc.steps: step2. Call SetEnableTransition. + * @tc.expected: MovingPhoto enable transition. + */ + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->mediaPlayer_)), IsMediaPlayerValid()) + .WillRepeatedly(Return(true)); + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->renderSurface_)), IsSurfaceValid()) + .WillRepeatedly(Return(true)); + movingphotoPattern->SetEnableTransition(true); + ASSERT_TRUE(movingphotoPattern->GetEnableTransition()); +} + +/** + * @tc.name: MovingPhotoPatternTest030 + * @tc.desc: Test MovingPhotoPattern SetPlaybackPeriod. + * @tc.type: FUNC + */ +HWTEST_F(MovingphotoTestNg, MovingPhotoPatternTest030, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create MovingPhoto and get MovingPhotoPattern. + */ + MovingPhotoModelNG movingphoto; + movingphoto.Create(AceType::MakeRefPtr()); + auto movingphotoNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(movingphotoNode, nullptr); + auto movingphotoPattern = movingphotoNode->GetPattern(); + ASSERT_NE(movingphotoPattern, nullptr); + + /** + * @tc.steps: step2. Call SetPlaybackPeriod. + * @tc.expected: MovingPhoto set period. + */ + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->mediaPlayer_)), IsMediaPlayerValid()) + .WillRepeatedly(Return(true)); + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->renderSurface_)), IsSurfaceValid()) + .WillRepeatedly(Return(true)); + ASSERT_FALSE(movingphotoPattern->SetPlaybackPeriod(300, 100)); + ASSERT_TRUE(movingphotoPattern->SetPlaybackPeriod(100, 300)); +} + +/** + * @tc.name: MovingPhotoPatternTest031 + * @tc.desc: Test MovingPhotoPattern EnableAutoPlay. + * @tc.type: FUNC + */ +HWTEST_F(MovingphotoTestNg, MovingPhotoPatternTest031, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create MovingPhoto and get MovingPhotoPattern. + */ + MovingPhotoModelNG movingphoto; + movingphoto.Create(AceType::MakeRefPtr()); + auto movingphotoNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(movingphotoNode, nullptr); + auto movingphotoPattern = movingphotoNode->GetPattern(); + ASSERT_NE(movingphotoPattern, nullptr); + + /** + * @tc.steps: step2. Call EnableAutoPlay. + * @tc.expected: MovingPhoto enable autoPlay. + */ + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->mediaPlayer_)), IsMediaPlayerValid()) + .WillRepeatedly(Return(true)); + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->renderSurface_)), IsSurfaceValid()) + .WillRepeatedly(Return(true)); + movingphotoPattern->isPlayByController_ = false; + movingphotoPattern->isPrepared_ = true; + movingphotoPattern->EnableAutoPlay(true); + ASSERT_TRUE(movingphotoPattern->GetPlayByController()); +} } //namespace OHOS::Ace::NG -- Gitee