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_generator.h"
18 #include "vsync_controller.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 class VSyncConnectionTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29
30 static inline sptr<VSyncController> vsyncController = nullptr;
31 static inline sptr<VSyncDistributor> vsyncDistributor = nullptr;
32 static inline sptr<VSyncGenerator> vsyncGenerator = nullptr;
33 static inline sptr<VSyncConnection> vsyncConnection = nullptr;
34 static constexpr const int32_t WAIT_SYSTEM_ABILITY_REPORT_DATA_SECONDS = 5;
35 };
36
SetUpTestCase()37 void VSyncConnectionTest::SetUpTestCase()
38 {
39 vsyncGenerator = CreateVSyncGenerator();
40 vsyncController = new VSyncController(vsyncGenerator, 0);
41 vsyncDistributor = new VSyncDistributor(vsyncController, "VSyncConnection");
42 vsyncConnection = new VSyncConnection(vsyncDistributor, "VSyncConnection");
43 }
44
TearDownTestCase()45 void VSyncConnectionTest::TearDownTestCase()
46 {
47 sleep(WAIT_SYSTEM_ABILITY_REPORT_DATA_SECONDS);
48 DestroyVSyncGenerator();
49 vsyncController = nullptr;
50 vsyncGenerator = nullptr;
51 vsyncDistributor = nullptr;
52 vsyncConnection = nullptr;
53 }
54
55 namespace {
56 /*
57 * Function: RequestNextVSync001
58 * Type: Function
59 * Rank: Important(2)
60 * EnvConditions: N/A
61 * CaseDescription: 1. call RequestNextVSync
62 */
63 HWTEST_F(VSyncConnectionTest, RequestNextVSync001, Function | MediumTest| Level3)
64 {
65 ASSERT_EQ(VSyncConnectionTest::vsyncConnection->RequestNextVSync(), VSYNC_ERROR_INVALID_ARGUMENTS);
66 }
67
68 /*
69 * Function: RequestNextVSync002
70 * Type: Function
71 * Rank: Important(2)
72 * EnvConditions: N/A
73 * CaseDescription: 1. call RequestNextVSync
74 */
75 HWTEST_F(VSyncConnectionTest, RequestNextVSync002, Function | MediumTest| Level3)
76 {
77 VSyncConnectionTest::vsyncDistributor->AddConnection(VSyncConnectionTest::vsyncConnection);
78 ASSERT_EQ(VSyncConnectionTest::vsyncConnection->RequestNextVSync(), VSYNC_ERROR_OK);
79 VSyncConnectionTest::vsyncDistributor->RemoveConnection(VSyncConnectionTest::vsyncConnection);
80 }
81
82 /*
83 * Function: RequestNextVSync003
84 * Type: Function
85 * Rank: Important(2)
86 * EnvConditions: N/A
87 * CaseDescription: 1. call RequestNextVSync
88 */
89 HWTEST_F(VSyncConnectionTest, RequestNextVSync003, Function | MediumTest| Level3)
90 {
91 ASSERT_EQ(VSyncConnectionTest::vsyncConnection->RequestNextVSync("unknown", 0), VSYNC_ERROR_INVALID_ARGUMENTS);
92 }
93
94 /*
95 * Function: SetVSyncRate001
96 * Type: Function
97 * Rank: Important(2)
98 * EnvConditions: N/A
99 * CaseDescription: 1. call SetVSyncRate
100 */
101 HWTEST_F(VSyncConnectionTest, SetVSyncRate001, Function | MediumTest| Level3)
102 {
103 ASSERT_EQ(VSyncConnectionTest::vsyncConnection->SetVSyncRate(-2), VSYNC_ERROR_INVALID_ARGUMENTS);
104 }
105
106 /*
107 * Function: SetVSyncRate002
108 * Type: Function
109 * Rank: Important(2)
110 * EnvConditions: N/A
111 * CaseDescription: 1. call SetVSyncRate
112 */
113 HWTEST_F(VSyncConnectionTest, SetVSyncRate002, Function | MediumTest| Level3)
114 {
115 VSyncConnectionTest::vsyncDistributor->AddConnection(VSyncConnectionTest::vsyncConnection);
116 ASSERT_EQ(VSyncConnectionTest::vsyncConnection->SetVSyncRate(1), VSYNC_ERROR_OK);
117 VSyncConnectionTest::vsyncDistributor->RemoveConnection(VSyncConnectionTest::vsyncConnection);
118 }
119
120 /*
121 * Function: GetReceiveFd001
122 * Type: Function
123 * Rank: Important(2)
124 * EnvConditions: N/A
125 * CaseDescription: 1. call GetReceiveFd
126 */
127 HWTEST_F(VSyncConnectionTest, GetReceiveFd001, Function | MediumTest| Level3)
128 {
129 int32_t fd = -1;
130 ASSERT_EQ(VSyncConnectionTest::vsyncConnection->GetReceiveFd(fd), VSYNC_ERROR_OK);
131 ASSERT_NE(fd, -1);
132 }
133 } // namespace
134 } // namespace Rosen
135 } // namespace OHOS
136