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