1 /*
2 * Copyright (C) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "video_sink_unittest.h"
17
18 namespace OHOS {
19 namespace Media {
20 namespace Pipeline {
21 using namespace std;
22 using namespace testing;
23 using namespace testing::ext;
24
25 static const int64_t WAITTIME_1 = 1000;
26 static const int64_t WAITTIME_2 = 50000;
27 static const int32_t DEFAULT_CAPACITY = 30;
28 static const double FRAMERATE = 1;
29 static const int32_t NUM_0 = 0;
30
SetUpTestCase(void)31 void VideoSinkUnitTest::SetUpTestCase(void)
32 {
33 }
34
TearDownTestCase(void)35 void VideoSinkUnitTest::TearDownTestCase(void)
36 {
37 }
38
SetUp(void)39 void VideoSinkUnitTest::SetUp(void)
40 {
41 sink_ = std::make_shared<VideoSink>();
42 }
43
TearDown(void)44 void VideoSinkUnitTest::TearDown(void)
45 {
46 sink_ = nullptr;
47 }
48
49 /**
50 * @tc.name : Test PerfRecord
51 * @tc.number: PerfRecord_001
52 * @tc.desc : Test perfRecorder_.Record(Plugins::Us2Ms(waitTime)) == PerfRecorder::FULL
53 */
54 HWTEST_F(VideoSinkUnitTest, PerfRecord_001, TestSize.Level0)
55 {
56 ASSERT_NE(sink_, nullptr);
57 sink_->SetPerfRecEnabled(true);
58 std::shared_ptr<EventReceiver> eventReceiver = std::make_shared<MockEventReceiver>();
59 sink_->SetEventReceiver(eventReceiver);
60 for (int i = 0; i < DEFAULT_CAPACITY; i++) {
61 sink_->PerfRecord(WAITTIME_1);
62 }
63 sink_->PerfRecord(WAITTIME_1);
64 EXPECT_EQ(sink_->perfRecorder_.list_.size(), 0);
65 }
66
67 /**
68 * @tc.name : Test RenderAtTimeLog
69 * @tc.number: RenderAtTimeLog_001
70 * @tc.desc : Test enableRenderAtTime_ == nullptr
71 */
72 HWTEST_F(VideoSinkUnitTest, RenderAtTimeLog_001, TestSize.Level0)
73 {
74 struct VideoSinkTestable : public VideoSink {
SetEnableRenderAtTimeOHOS::Media::Pipeline::VideoSinkTestable75 void SetEnableRenderAtTime(bool val) { enableRenderAtTime_ = val; }
76 };
77 VideoSinkTestable testSink;
78 testSink.SetEnableRenderAtTime(false);
79 EXPECT_EQ(testSink.enableRenderAtTime_, false);
80 testSink.RenderAtTimeLog(WAITTIME_2);
81 }
82
83 /**
84 * @tc.name : Test InitWaitPeriod
85 * @tc.number: InitWaitPeriod_001
86 * @tc.desc : Test initialVideoFrameRate > 1e-9
87 */
88 HWTEST_F(VideoSinkUnitTest, InitWaitPeriod_001, TestSize.Level0)
89 {
90 ASSERT_NE(sink_, nullptr);
91 auto syncCenter = std::make_shared<MediaSyncManager>();
92 syncCenter->SetInitialVideoFrameRate(FRAMERATE);
93 sink_->SetSyncCenter(syncCenter);
94 sink_->InitWaitPeriod();
95 EXPECT_NE(sink_->initialVideoWaitPeriod_, NUM_0);
96 }
97
98 /**
99 * @tc.name : Test SetMediaMuted
100 * @tc.number: SetMediaMuted
101 * @tc.desc : Test SetMediaMuted
102 */
103 HWTEST_F(VideoSinkUnitTest, SetMediaMuted, TestSize.Level0)
104 {
105 ASSERT_NE(sink_, nullptr);
106 sink_->isMuted_ = false;
107 sink_->needDropOnMute_ = false;
108 sink_->SetMediaMuted(true);
109 EXPECT_EQ(sink_->needDropOnMute_, true);
110 EXPECT_EQ(sink_->isMuted_, true);
111 }
112 } // namespace Pipeline
113 } // namespace Media
114 } // namespace OHOS
115