1 /*
2 * Copyright (c) 2024 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 <gtest/gtest.h>
17 #include <test_header.h>
18
19 #define private public
20 #include "rs_frame_rate_vote.h"
21 #undef private
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Rosen {
28 namespace {
29 }
30 class RSVideoFrameRateVoteTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 void SetUp();
35 void TearDown();
36
37 void VoteCallback(uint64_t avg1, uint32_t avg2);
38 void ReleaseCallback(int64_t avg);
39 public:
40 int64_t voteCallbackResult_ {0};
41 int64_t releaseCallbackResult_ {0};
42 };
43
SetUpTestCase()44 void RSVideoFrameRateVoteTest::SetUpTestCase() {}
TearDownTestCase()45 void RSVideoFrameRateVoteTest::TearDownTestCase() {}
SetUp()46 void RSVideoFrameRateVoteTest::SetUp() {}
TearDown()47 void RSVideoFrameRateVoteTest::TearDown() {}
48
VoteCallback(uint64_t avg1,uint32_t avg2)49 void RSVideoFrameRateVoteTest::VoteCallback(uint64_t avg1, uint32_t avg2)
50 {
51 voteCallbackResult_ = static_cast<int64_t>(avg1) + static_cast<int64_t>(avg2);
52 }
53
ReleaseCallback(int64_t avg)54 void RSVideoFrameRateVoteTest::ReleaseCallback(int64_t avg)
55 {
56 releaseCallbackResult_ = avg;
57 }
58
59 /**
60 * @tc.name: RSVideoFrameRateVote001
61 * @tc.desc: Verify the result of RSVideoFrameRate function
62 * @tc.type: FUNC
63 * @tc.require:
64 */
65 HWTEST_F(RSVideoFrameRateVoteTest, RSVideoFrameRateVote001, Function | SmallTest | Level1)
66 {
67 std::shared_ptr<RSVideoFrameRateVote> rsVideoFrameRateVote = std::make_shared<RSVideoFrameRateVote>(0,
68 nullptr, nullptr);
69 ASSERT_EQ(rsVideoFrameRateVote->surfaceNodeId_, 0);
70 ASSERT_EQ(rsVideoFrameRateVote->voteCallback_, nullptr);
71 ASSERT_EQ(rsVideoFrameRateVote->releaseCallback_, nullptr);
72 rsVideoFrameRateVote = nullptr;
73 }
74
75 /**
76 * @tc.name: StartVideoFrameRateVote001
77 * @tc.desc: Verify the result of StartVideoFrameRateVote function
78 * @tc.type: FUNC
79 * @tc.require:
80 */
81 HWTEST_F(RSVideoFrameRateVoteTest, StartVideoFrameRateVote001, Function | SmallTest | Level1)
82 {
83 std::shared_ptr<RSVideoFrameRateVote> rsVideoFrameRateVote = std::make_shared<RSVideoFrameRateVote>(0,
84 nullptr, nullptr);
85 rsVideoFrameRateVote->StartVideoFrameRateVote(30.0);
86 ASSERT_EQ(rsVideoFrameRateVote->lastRate_, 30);
87 rsVideoFrameRateVote = nullptr;
88 }
89
90 /**
91 * @tc.name: VoteVideoFrameRate001
92 * @tc.desc: Verify the result of VoteVideoFrameRate function
93 * @tc.type: FUNC
94 * @tc.require:
95 */
96 HWTEST_F(RSVideoFrameRateVoteTest, VoteVideoFrameRate001, Function | SmallTest | Level1)
97 {
98 std::shared_ptr<RSVideoFrameRateVote> rsVideoFrameRateVote = std::make_shared<RSVideoFrameRateVote>(0,
99 nullptr, nullptr);
100 rsVideoFrameRateVote->VoteVideoFrameRate(30.0);
101 ASSERT_EQ(rsVideoFrameRateVote->lastRate_, 30);
102 rsVideoFrameRateVote->VoteVideoFrameRate(0.0);
103 ASSERT_EQ(rsVideoFrameRateVote->lastRate_, 30);
104 rsVideoFrameRateVote->VoteVideoFrameRate(300.0);
105 ASSERT_EQ(rsVideoFrameRateVote->lastRate_, 30);
106 rsVideoFrameRateVote->VoteVideoFrameRate(30.0);
107 ASSERT_EQ(rsVideoFrameRateVote->lastRate_, 30);
108 rsVideoFrameRateVote->VoteVideoFrameRate(60.0);
109 ASSERT_EQ(rsVideoFrameRateVote->lastRate_, 60);
110 rsVideoFrameRateVote = nullptr;
111 }
112
113 /**
114 * @tc.name: SendDelayTask001
115 * @tc.desc: Verify the result of SendDelayTask function
116 * @tc.type: FUNC
117 * @tc.require:
118 */
119 HWTEST_F(RSVideoFrameRateVoteTest, SendDelayTask001, Function | SmallTest | Level1)
120 {
121 releaseCallbackResult_ = 0;
122 std::shared_ptr<RSVideoFrameRateVote> rsVideoFrameRateVote = std::make_shared<RSVideoFrameRateVote>(0,
123 nullptr, nullptr);
__anon53d3fd950202(uint64_t id) 124 rsVideoFrameRateVote->releaseCallback_ = [this](uint64_t id) { this->ReleaseCallback(id); };
125 rsVideoFrameRateVote->surfaceNodeId_ = 2;
126 rsVideoFrameRateVote->SendDelayTask();
127 ASSERT_NE(rsVideoFrameRateVote->taskHandler_, nullptr);
128 sleep(2);
129 ASSERT_EQ(releaseCallbackResult_, 2);
130 rsVideoFrameRateVote = nullptr;
131 }
132
133 /**
134 * @tc.name: CancelDelayTask001
135 * @tc.desc: Verify the result of CancelDelayTask function
136 * @tc.type: FUNC
137 * @tc.require:
138 */
139 HWTEST_F(RSVideoFrameRateVoteTest, CancelDelayTask001, Function | SmallTest | Level1)
140 {
141 releaseCallbackResult_ = 0;
142 std::shared_ptr<RSVideoFrameRateVote> rsVideoFrameRateVote = std::make_shared<RSVideoFrameRateVote>(0,
143 nullptr, nullptr);
__anon53d3fd950302(uint64_t id) 144 rsVideoFrameRateVote->releaseCallback_ = [this](uint64_t id) { this->ReleaseCallback(id); };
145 rsVideoFrameRateVote->surfaceNodeId_ = 2;
146 rsVideoFrameRateVote->SendDelayTask();
147 ASSERT_NE(rsVideoFrameRateVote->taskHandler_, nullptr);
148 rsVideoFrameRateVote->CancelDelayTask();
149 ASSERT_EQ(rsVideoFrameRateVote->taskHandler_, nullptr);
150 sleep(2);
151 ASSERT_EQ(releaseCallbackResult_, 0);
152 rsVideoFrameRateVote = nullptr;
153 }
154
155 /**
156 * @tc.name: DoVoteCallback001
157 * @tc.desc: Verify the result of DoVoteCallback function
158 * @tc.type: FUNC
159 * @tc.require:
160 */
161 HWTEST_F(RSVideoFrameRateVoteTest, DoVoteCallback001, Function | SmallTest | Level1)
162 {
163 voteCallbackResult_ = 0;
164 std::shared_ptr<RSVideoFrameRateVote> rsVideoFrameRateVote = std::make_shared<RSVideoFrameRateVote>(0,
165 nullptr, nullptr);
166 ASSERT_EQ(rsVideoFrameRateVote->voteCallback_, nullptr);
167 rsVideoFrameRateVote->DoVoteCallback(0);
__anon53d3fd950402(uint64_t id, uint32_t rate) 168 rsVideoFrameRateVote->voteCallback_ = [this](uint64_t id, uint32_t rate) { this->VoteCallback(id, rate); };
169 rsVideoFrameRateVote->surfaceNodeId_ = 2;
170 rsVideoFrameRateVote->DoVoteCallback(2);
171 ASSERT_EQ(voteCallbackResult_, 4);
172 rsVideoFrameRateVote->DoVoteCallback(3);
173 ASSERT_EQ(voteCallbackResult_, 5);
174 rsVideoFrameRateVote = nullptr;
175 }
176
177 /**
178 * @tc.name: DoReleaseCallback001
179 * @tc.desc: Verify the result of DoReleaseCallback function
180 * @tc.type: FUNC
181 * @tc.require:
182 */
183 HWTEST_F(RSVideoFrameRateVoteTest, DoReleaseCallback001, Function | SmallTest | Level1)
184 {
185 releaseCallbackResult_ = 0;
186 std::shared_ptr<RSVideoFrameRateVote> rsVideoFrameRateVote = std::make_shared<RSVideoFrameRateVote>(0,
187 nullptr, nullptr);
188 ASSERT_EQ(rsVideoFrameRateVote->releaseCallback_, nullptr);
189 rsVideoFrameRateVote->DoReleaseCallback();
__anon53d3fd950502(uint64_t id) 190 rsVideoFrameRateVote->releaseCallback_ = [this](uint64_t id) { this->ReleaseCallback(id); };
191 rsVideoFrameRateVote->surfaceNodeId_ = 2;
192 rsVideoFrameRateVote->DoReleaseCallback();
193 ASSERT_EQ(releaseCallbackResult_, 2);
194 rsVideoFrameRateVote = nullptr;
195 }
196 } // namespace Rosen
197 } // namespace OHOS