• 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 #include "hgm_core.h"
21 #include "surface_buffer_impl.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace {
29 }
30 class RSFrameRateVoteTest : public testing::Test {
31 public:
32     static void SetUpTestCase();
33     static void TearDownTestCase();
34     void SetUp();
35     void TearDown();
36 };
37 
SetUpTestCase()38 void RSFrameRateVoteTest::SetUpTestCase() {}
TearDownTestCase()39 void RSFrameRateVoteTest::TearDownTestCase() {}
SetUp()40 void RSFrameRateVoteTest::SetUp() {}
TearDown()41 void RSFrameRateVoteTest::TearDown() {}
42 
43 /**
44  * @tc.name: VideoFrameRateVote001
45  * @tc.desc: Verify the result of VideoFrameRateVote function
46  * @tc.type: FUNC
47  * @tc.require:
48  */
49 HWTEST_F(RSFrameRateVoteTest, VideoFrameRateVote001, Function | SmallTest | Level1)
50 {
51     sptr<SurfaceBuffer> nullBuffer = nullptr;
52     sptr<SurfaceBuffer> buffer = new SurfaceBufferImpl();
53     DelayedSingleton<RSFrameRateVote>::GetInstance()->isSwitchOn_ = false;
54     DelayedSingleton<RSFrameRateVote>::GetInstance()->VideoFrameRateVote(
55         1000, OHSurfaceSource::OH_SURFACE_SOURCE_DEFAULT, nullBuffer);
56     usleep(500000);
57     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.size(), 0);
58     DelayedSingleton<RSFrameRateVote>::GetInstance()->isSwitchOn_ = true;
59     DelayedSingleton<RSFrameRateVote>::GetInstance()->VideoFrameRateVote(
60         1000, OHSurfaceSource::OH_SURFACE_SOURCE_DEFAULT, nullBuffer);
61     usleep(500000);
62     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.size(), 0);
63     DelayedSingleton<RSFrameRateVote>::GetInstance()->isSwitchOn_ = false;
64     DelayedSingleton<RSFrameRateVote>::GetInstance()->VideoFrameRateVote(
65         1000, OHSurfaceSource::OH_SURFACE_SOURCE_VIDEO, nullBuffer);
66     usleep(500000);
67     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.size(), 0);
68     DelayedSingleton<RSFrameRateVote>::GetInstance()->isSwitchOn_ = false;
69     DelayedSingleton<RSFrameRateVote>::GetInstance()->VideoFrameRateVote(
70         1000, OHSurfaceSource::OH_SURFACE_SOURCE_DEFAULT, buffer);
71     usleep(500000);
72     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.size(), 0);
73     DelayedSingleton<RSFrameRateVote>::GetInstance()->isSwitchOn_ = false;
74     DelayedSingleton<RSFrameRateVote>::GetInstance()->VideoFrameRateVote(
75         1000, OHSurfaceSource::OH_SURFACE_SOURCE_VIDEO, buffer);
76     usleep(500000);
77     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.size(), 0);
78     DelayedSingleton<RSFrameRateVote>::GetInstance()->isSwitchOn_ = true;
79     DelayedSingleton<RSFrameRateVote>::GetInstance()->VideoFrameRateVote(
80         1000, OHSurfaceSource::OH_SURFACE_SOURCE_DEFAULT, buffer);
81     usleep(500000);
82     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.size(), 0);
83     DelayedSingleton<RSFrameRateVote>::GetInstance()->isSwitchOn_ = true;
84     DelayedSingleton<RSFrameRateVote>::GetInstance()->VideoFrameRateVote(
85         1000, OHSurfaceSource::OH_SURFACE_SOURCE_VIDEO, nullBuffer);
86     usleep(500000);
87     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.size(), 0);
88     DelayedSingleton<RSFrameRateVote>::GetInstance()->isSwitchOn_ = true;
89     DelayedSingleton<RSFrameRateVote>::GetInstance()->VideoFrameRateVote(
90         1000, OHSurfaceSource::OH_SURFACE_SOURCE_VIDEO, buffer);
91     usleep(500000);
92     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.size(), 1);
93 }
94 
95 /**
96  * @tc.name: ReleaseSurfaceMap001
97  * @tc.desc: Verify the result of ReleaseSurfaceMap function
98  * @tc.type: FUNC
99  * @tc.require:
100  */
101 HWTEST_F(RSFrameRateVoteTest, ReleaseSurfaceMap001, Function | SmallTest | Level1)
102 {
103     std::shared_ptr<RSVideoFrameRateVote> rsVideoFrameRateVote = std::make_shared<RSVideoFrameRateVote>(0,
104         nullptr, nullptr);
105     DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.insert(
106         std::pair<uint64_t, std::shared_ptr<RSVideoFrameRateVote>>(1001, rsVideoFrameRateVote));
107     DelayedSingleton<RSFrameRateVote>::GetInstance()->ReleaseSurfaceMap(1000);
108     sleep(1);
109     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.size(), 1);
110     DelayedSingleton<RSFrameRateVote>::GetInstance()->ReleaseSurfaceMap(1001);
111     sleep(1);
112     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoFrameRateVote_.size(), 0);
113     rsVideoFrameRateVote = nullptr;
114 }
115 
116 /**
117  * @tc.name: SurfaceVideoVote001
118  * @tc.desc: Verify the result of SurfaceVideoVote function
119  * @tc.type: FUNC
120  * @tc.require:
121  */
122 HWTEST_F(RSFrameRateVoteTest, SurfaceVideoVote001, Function | SmallTest | Level1)
123 {
124     std::shared_ptr<RSVideoFrameRateVote> rsVideoFrameRateVote = std::make_shared<RSVideoFrameRateVote>(0,
125         nullptr, nullptr);
126     DelayedSingleton<RSFrameRateVote>::GetInstance()->SurfaceVideoVote(1000, 30);
127     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoRate_.size(), 1);
128     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoRate_[1000], 30);
129     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->lastVotedRate_, 30);
130     DelayedSingleton<RSFrameRateVote>::GetInstance()->SurfaceVideoVote(1001, 60);
131     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoRate_.size(), 2);
132     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoRate_[1001], 60);
133     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->lastVotedRate_, 60);
134     DelayedSingleton<RSFrameRateVote>::GetInstance()->SurfaceVideoVote(1002, 30);
135     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoRate_.size(), 3);
136     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoRate_[1002], 30);
137     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->lastVotedRate_, 60);
138     DelayedSingleton<RSFrameRateVote>::GetInstance()->SurfaceVideoVote(1000, 0);
139     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoRate_.size(), 2);
140     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->lastVotedRate_, 60);
141     DelayedSingleton<RSFrameRateVote>::GetInstance()->SurfaceVideoVote(1001, 0);
142     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoRate_.size(), 1);
143     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->lastVotedRate_, 30);
144     DelayedSingleton<RSFrameRateVote>::GetInstance()->SurfaceVideoVote(1002, 0);
145     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->surfaceVideoRate_.size(), 0);
146     ASSERT_EQ(DelayedSingleton<RSFrameRateVote>::GetInstance()->lastVotedRate_, 0);
147     rsVideoFrameRateVote = nullptr;
148 }
149 
150 /**
151  * @tc.name: VoteRate001
152  * @tc.desc: Verify the result of VoteRate function
153  * @tc.type: FUNC
154  * @tc.require:
155  */
156 HWTEST_F(RSFrameRateVoteTest, VoteRate001, Function | SmallTest | Level1)
157 {
158     ASSERT_FALSE(DelayedSingleton<RSFrameRateVote>::GetInstance()->isVoted_);
159     DelayedSingleton<RSFrameRateVote>::GetInstance()->VoteRate(DEFAULT_PID, "VOTER_VIDEO", 30);
160     ASSERT_TRUE(DelayedSingleton<RSFrameRateVote>::GetInstance()->isVoted_);
161 }
162 
163 /**
164  * @tc.name: CancelVoteRate001
165  * @tc.desc: Verify the result of CancelVoteRate function
166  * @tc.type: FUNC
167  * @tc.require:
168  */
169 HWTEST_F(RSFrameRateVoteTest, CancelVoteRate001, Function | SmallTest | Level1)
170 {
171     DelayedSingleton<RSFrameRateVote>::GetInstance()->isVoted_ = true;
172     ASSERT_TRUE(DelayedSingleton<RSFrameRateVote>::GetInstance()->isVoted_);
173     DelayedSingleton<RSFrameRateVote>::GetInstance()->CancelVoteRate(DEFAULT_PID, "VOTER_VIDEO");
174     ASSERT_FALSE(DelayedSingleton<RSFrameRateVote>::GetInstance()->isVoted_);
175 }
176 
177 /**
178  * @tc.name: NotifyRefreshRateEvent001
179  * @tc.desc: Verify the result of NotifyRefreshRateEvent function
180  * @tc.type: FUNC
181  * @tc.require:
182  */
183 HWTEST_F(RSFrameRateVoteTest, NotifyRefreshRateEvent001, Function | SmallTest | Level1)
184 {
185     EventInfo eventInfo1 = {
186         .eventName = "VOTER_VIDEO",
187         .eventStatus = true,
188         .minRefreshRate = 60,
189         .maxRefreshRate = 60,
190     };
191     if (DelayedSingleton<RSFrameRateVote>::GetInstance() == nullptr) {
192         return;
193     }
194     DelayedSingleton<RSFrameRateVote>::GetInstance()->NotifyRefreshRateEvent(DEFAULT_PID, eventInfo1);
195     ASSERT_FALSE(DelayedSingleton<RSFrameRateVote>::GetInstance()->isVoted_);
196     EventInfo eventInfo2 = {
197         .eventName = "VOTER_VIDEO",
198         .eventStatus = false,
199     };
200     DelayedSingleton<RSFrameRateVote>::GetInstance()->NotifyRefreshRateEvent(DEFAULT_PID, eventInfo2);
201     ASSERT_FALSE(DelayedSingleton<RSFrameRateVote>::GetInstance()->isVoted_);
202     DelayedSingleton<RSFrameRateVote>::GetInstance()->NotifyRefreshRateEvent(DEFAULT_PID, eventInfo2);
203     pid_t pid1 = 1;
204     DelayedSingleton<RSFrameRateVote>::GetInstance()->NotifyRefreshRateEvent(pid1, eventInfo2);
205 }
206 } // namespace Rosen
207 } // namespace OHOS