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