• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "media_synchronous_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 INVALID_Time = -1;
26 
SetUpTestCase(void)27 void MediaSynchronousSinkUnitTest::SetUpTestCase(void)
28 {
29 }
30 
TearDownTestCase(void)31 void MediaSynchronousSinkUnitTest::TearDownTestCase(void)
32 {
33 }
34 
SetUp(void)35 void MediaSynchronousSinkUnitTest::SetUp(void)
36 {
37     sink_ = std::make_shared<VideoSink>();
38 }
39 
TearDown(void)40 void MediaSynchronousSinkUnitTest::TearDown(void)
41 {
42     sink_ = nullptr;
43 }
44 
45 /**
46  * @tc.name  : Test WriteToPluginRefTimeSync
47  * @tc.number: WriteToPluginRefTimeSync_001
48  * @tc.desc  : Test hasReportedPreroll_ == false
49  *             Test syncCenter_ != nullptr
50  *             Test waitForPrerolled_ == true
51  *             Test waitPrerolledTimeout_ == -1
52  */
53 HWTEST_F(MediaSynchronousSinkUnitTest, WriteToPluginRefTimeSync_001, TestSize.Level0)
54 {
55     ASSERT_NE(sink_, nullptr);
56     // Test hasReportedPreroll_ == false
57     sink_->hasReportedPreroll_ = false;
58     // Test waitForPrerolled_ == true
59     sink_->waitForPrerolled_ = true;
60     // Test syncCenter_ != nullptr
61     auto syncCenter_ = std::make_shared<MediaSyncManager>();
62     sink_->SetSyncCenter(syncCenter_);
63     std::shared_ptr<OHOS::Media::AVBuffer> buffer = nullptr;
64     // Test waitPrerolledTimeout_ == -1
65     sink_->waitPrerolledTimeout_ = INVALID_Time;
66     sink_->WriteToPluginRefTimeSync(buffer);
67     EXPECT_TRUE(sink_->hasReportedPreroll_);
68     EXPECT_FALSE(sink_->waitForPrerolled_);
69 }
70 
71 /**
72  * @tc.name  : Test OnInterrupted
73  * @tc.number: OnInterrupted_001
74  * @tc.desc  : Test default
75  */
76 HWTEST_F(MediaSynchronousSinkUnitTest, OnInterrupted_001, TestSize.Level0)
77 {
78     ASSERT_NE(sink_, nullptr);
79     bool isInterruptNeeded = true;
80     sink_->OnInterrupted(isInterruptNeeded);
81     EXPECT_EQ(sink_->isInterruptNeeded_, isInterruptNeeded);
82     EXPECT_EQ(sink_->waitForPrerolled_, false);
83 }
84 
85 } // namespace Pipeline
86 } // namespace Media
87 } // namespace OHOS
88