1 /*
2 * Copyright (c) 2021 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 #include <gtest/gtest.h>
16 #include "vsync_distributor.h"
17 #include "vsync_controller.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24 class VSyncDistributorTest : public testing::Test {
25 public:
26 static void SetUpTestCase();
27 static void TearDownTestCase();
28
29 static inline sptr<VSyncController> vsyncController = nullptr;
30 static inline sptr<VSyncDistributor> vsyncDistributor = nullptr;
31 static inline sptr<VSyncGenerator> vsyncGenerator = nullptr;
32 };
33
SetUpTestCase()34 void VSyncDistributorTest::SetUpTestCase()
35 {
36 vsyncGenerator = CreateVSyncGenerator();
37 vsyncController = new VSyncController(vsyncGenerator, 0);
38 vsyncDistributor = new VSyncDistributor(vsyncController, "VSyncConnection");
39 }
40
TearDownTestCase()41 void VSyncDistributorTest::TearDownTestCase()
42 {
43 vsyncDistributor = nullptr;
44 vsyncController = nullptr;
45 vsyncGenerator = nullptr;
46 DestroyVSyncGenerator();
47 }
48
49 namespace {
50 /*
51 * Function: AddConnection001
52 * Type: Function
53 * Rank: Important(2)
54 * EnvConditions: N/A
55 * CaseDescription: 1. call AddConnection
56 */
57 HWTEST_F(VSyncDistributorTest, AddConnection001, Function | MediumTest| Level3)
58 {
59 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->AddConnection(nullptr), VSYNC_ERROR_NULLPTR);
60 }
61
62 /*
63 * Function: AddConnection002
64 * Type: Function
65 * Rank: Important(2)
66 * EnvConditions: N/A
67 * CaseDescription: 1. call AddConnection
68 */
69 HWTEST_F(VSyncDistributorTest, AddConnection002, Function | MediumTest| Level3)
70 {
71 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
72 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->AddConnection(conn), VSYNC_ERROR_OK);
73 }
74
75 /*
76 * Function: RemoveConnection001
77 * Type: Function
78 * Rank: Important(2)
79 * EnvConditions: N/A
80 * CaseDescription: 1. call RemoveConnection
81 */
82 HWTEST_F(VSyncDistributorTest, RemoveConnection001, Function | MediumTest| Level3)
83 {
84 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RemoveConnection(nullptr), VSYNC_ERROR_NULLPTR);
85 }
86
87 /*
88 * Function: RemoveConnection002
89 * Type: Function
90 * Rank: Important(2)
91 * EnvConditions: N/A
92 * CaseDescription: 1. call RemoveConnection
93 */
94 HWTEST_F(VSyncDistributorTest, RemoveConnection002, Function | MediumTest| Level3)
95 {
96 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
97 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RemoveConnection(conn), VSYNC_ERROR_INVALID_ARGUMENTS);
98 }
99
100 /*
101 * Function: RemoveConnection003
102 * Type: Function
103 * Rank: Important(2)
104 * EnvConditions: N/A
105 * CaseDescription: 1. call RemoveConnection
106 */
107 HWTEST_F(VSyncDistributorTest, RemoveConnection003, Function | MediumTest| Level3)
108 {
109 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
110 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
111 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RemoveConnection(conn), VSYNC_ERROR_OK);
112 }
113
114 /*
115 * Function: RequestNextVSync001
116 * Type: Function
117 * Rank: Important(2)
118 * EnvConditions: N/A
119 * CaseDescription: 1. call RequestNextVSync
120 */
121 HWTEST_F(VSyncDistributorTest, RequestNextVSync001, Function | MediumTest| Level3)
122 {
123 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(nullptr), VSYNC_ERROR_NULLPTR);
124 }
125
126 /*
127 * Function: RequestNextVSync002
128 * Type: Function
129 * Rank: Important(2)
130 * EnvConditions: N/A
131 * CaseDescription: 1. call RequestNextVSync
132 */
133 HWTEST_F(VSyncDistributorTest, RequestNextVSync002, Function | MediumTest| Level3)
134 {
135 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
136 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(conn), VSYNC_ERROR_INVALID_ARGUMENTS);
137 }
138
139 /*
140 * Function: RequestNextVSync003
141 * Type: Function
142 * Rank: Important(2)
143 * EnvConditions: N/A
144 * CaseDescription: 1. call RequestNextVSync
145 */
146 HWTEST_F(VSyncDistributorTest, RequestNextVSync003, Function | MediumTest| Level3)
147 {
148 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
149 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
150 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(conn), VSYNC_ERROR_OK);
151 }
152
153 /*
154 * Function: SetVSyncRate001
155 * Type: Function
156 * Rank: Important(2)
157 * EnvConditions: N/A
158 * CaseDescription: 1. call SetVSyncRate
159 */
160 HWTEST_F(VSyncDistributorTest, SetVSyncRate001, Function | MediumTest| Level3)
161 {
162 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(0, nullptr), VSYNC_ERROR_INVALID_ARGUMENTS);
163 }
164
165 /*
166 * Function: SetVSyncRate002
167 * Type: Function
168 * Rank: Important(2)
169 * EnvConditions: N/A
170 * CaseDescription: 1. call SetVSyncRate
171 */
172 HWTEST_F(VSyncDistributorTest, SetVSyncRate002, Function | MediumTest| Level3)
173 {
174 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
175 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
176 }
177
178 /*
179 * Function: SetVSyncRate003
180 * Type: Function
181 * Rank: Important(2)
182 * EnvConditions: N/A
183 * CaseDescription: 1. call SetVSyncRate
184 */
185 HWTEST_F(VSyncDistributorTest, SetVSyncRate003, Function | MediumTest| Level3)
186 {
187 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
188 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
189 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_OK);
190 }
191
192 /*
193 * Function: SetVSyncRate004
194 * Type: Function
195 * Rank: Important(2)
196 * EnvConditions: N/A
197 * CaseDescription: 1. call SetVSyncRate
198 */
199 HWTEST_F(VSyncDistributorTest, SetVSyncRate004, Function | MediumTest| Level3)
200 {
201 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
202 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
203 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_OK);
204 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
205 }
206
207 /*
208 * Function: SetHighPriorityVSyncRate001
209 * Type: Function
210 * Rank: Important(2)
211 * EnvConditions: N/A
212 * CaseDescription: 1. call SetHighPriorityVSyncRate with abnormal parameters and check ret
213 */
214 HWTEST_F(VSyncDistributorTest, SetHighPriorityVSyncRate001, Function | MediumTest| Level3)
215 {
216 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(0, nullptr),
217 VSYNC_ERROR_INVALID_ARGUMENTS);
218 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, nullptr),
219 VSYNC_ERROR_INVALID_ARGUMENTS);
220 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
221 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
222 }
223
224 /*
225 * Function: SetHighPriorityVSyncRate002
226 * Type: Function
227 * Rank: Important(2)
228 * EnvConditions: N/A
229 * CaseDescription: 1. call SetHighPriorityVSyncRate with normal parameters and check ret
230 */
231 HWTEST_F(VSyncDistributorTest, SetHighPriorityVSyncRate002, Function | MediumTest| Level3)
232 {
233 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
234 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
235 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, conn), VSYNC_ERROR_OK);
236 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
237 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(2, conn), VSYNC_ERROR_OK);
238 }
239
240 /*
241 * Function: GetVSyncConnectionInfos001
242 * Type: Function
243 * Rank: Important(2)
244 * EnvConditions: N/A
245 * CaseDescription: 1. call GetVSyncConnectionInfos and check ret
246 */
247 HWTEST_F(VSyncDistributorTest, GetVSyncConnectionInfos001, Function | MediumTest| Level3)
248 {
249 std::vector<ConnectionInfo> infos;
250 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->GetVSyncConnectionInfos(infos), VSYNC_ERROR_OK);
251 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
252 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
253 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->GetVSyncConnectionInfos(infos), VSYNC_ERROR_OK);
254 }
255 } // namespace
256 } // namespace Rosen
257 } // namespace OHOS