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 <vsync_station.h>
17 #include <gtest/gtest.h>
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24 class VsyncStationTest : public testing::Test {
25 public:
26 static void SetUpTestCase();
27 static void TearDownTestCase();
28 void SetUp() override;
29 void TearDown() override;
30 };
31
SetUpTestCase()32 void VsyncStationTest::SetUpTestCase()
33 {
34 }
35
TearDownTestCase()36 void VsyncStationTest::TearDownTestCase()
37 {
38 }
39
SetUp()40 void VsyncStationTest::SetUp()
41 {
42 }
43
TearDown()44 void VsyncStationTest::TearDown()
45 {
46 }
47
48 namespace {
49 /**
50 * @tc.name: RequestVsyncOneWindow
51 * @tc.desc: RequestVsyncOneWindow Test
52 * @tc.type: FUNC
53 */
54 HWTEST_F(VsyncStationTest, RequestVsyncOneWindow, Function | SmallTest | Level3)
55 {
56 NodeId nodeId = 0;
57 std::shared_ptr<VsyncStation> vsyncStation = std::make_shared<VsyncStation>(nodeId);
58 std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
59 ASSERT_NE(vsyncStation, nullptr);
60 vsyncStation->RequestVsync(vsyncCallback);
61 }
62
63 /**
64 * @tc.name: RequestVsyncMultiWindow
65 * @tc.desc: RequestVsyncMultiWindow Test
66 * @tc.type: FUNC
67 */
68 HWTEST_F(VsyncStationTest, RequestVsyncMultiWindow, Function | SmallTest | Level3)
69 {
70 NodeId nodeId0 = 0;
71 std::shared_ptr<VsyncStation> vsyncStation0 = std::make_shared<VsyncStation>(nodeId0);
72 std::shared_ptr<VsyncCallback> vsyncCallback0 = std::make_shared<VsyncCallback>();
73 ASSERT_NE(vsyncStation0, nullptr);
74 vsyncStation0->RequestVsync(vsyncCallback0);
75 NodeId nodeId1 = 1;
76 std::shared_ptr<VsyncStation> vsyncStation1 = std::make_shared<VsyncStation>(nodeId1);
77 std::shared_ptr<VsyncCallback> vsyncCallback1 = std::make_shared<VsyncCallback>();
78 ASSERT_NE(vsyncStation1, nullptr);
79 vsyncStation1->RequestVsync(vsyncCallback1);
80 }
81
82 /**
83 * @tc.name: GetFrameRateLinkerId
84 * @tc.desc: GetFrameRateLinkerId Test
85 * @tc.type: FUNC
86 */
87 HWTEST_F(VsyncStationTest, GetFrameRateLinkerId, Function | SmallTest | Level3)
88 {
89 NodeId nodeId0 = 0;
90 std::shared_ptr<VsyncStation> vsyncStation0 = std::make_shared<VsyncStation>(nodeId0);
91 ASSERT_NE(vsyncStation0, nullptr);
92 ASSERT_NE(-1, vsyncStation0->GetFrameRateLinkerId());
93 NodeId nodeId1 = 1;
94 std::shared_ptr<VsyncStation> vsyncStation1 = std::make_shared<VsyncStation>(nodeId1);
95 ASSERT_NE(vsyncStation1, nullptr);
96 ASSERT_NE(-1, vsyncStation1->GetFrameRateLinkerId());
97 }
98
99 /**
100 * @tc.name: FlushFrameRate
101 * @tc.desc: FlushFrameRate Test
102 * @tc.type: FUNC
103 */
104 HWTEST_F(VsyncStationTest, FlushFrameRate, Function | SmallTest | Level3)
105 {
106 NodeId nodeId0 = 0;
107 std::shared_ptr<VsyncStation> vsyncStation0 = std::make_shared<VsyncStation>(nodeId0);
108 ASSERT_NE(vsyncStation0, nullptr);
109 uint32_t rate0 = 60;
110 int32_t animatorExpectedFrameRate = -1;
111 vsyncStation0->FlushFrameRate(rate0, animatorExpectedFrameRate);
112 NodeId nodeId1 = 1;
113 std::shared_ptr<VsyncStation> vsyncStation1 = std::make_shared<VsyncStation>(nodeId1);
114 ASSERT_NE(vsyncStation1, nullptr);
115 uint32_t rate1 = 120;
116 vsyncStation1->FlushFrameRate(rate1, animatorExpectedFrameRate);
117 }
118
119 /**
120 * @tc.name: SetFrameRateLinkerEnable
121 * @tc.desc: SetFrameRateLinkerEnable Test
122 * @tc.type: FUNC
123 */
124 HWTEST_F(VsyncStationTest, SetFrameRateLinkerEnable, Function | SmallTest | Level3)
125 {
126 NodeId nodeId0 = 0;
127 std::shared_ptr<VsyncStation> vsyncStation0 = std::make_shared<VsyncStation>(nodeId0);
128 ASSERT_NE(vsyncStation0, nullptr);
129 bool enable0 = false;
130 vsyncStation0->SetFrameRateLinkerEnable(enable0);
131 NodeId nodeId1 = 1;
132 std::shared_ptr<VsyncStation> vsyncStation1 = std::make_shared<VsyncStation>(nodeId1);
133 ASSERT_NE(vsyncStation1, nullptr);
134 bool enable1 = true;
135 vsyncStation1->SetFrameRateLinkerEnable(enable1);
136 }
137
138 /**
139 * @tc.name: SetUiDvsyncSwitch
140 * @tc.desc: SetUiDvsyncSwitch Test
141 * @tc.type: FUNC
142 */
143 HWTEST_F(VsyncStationTest, SetUiDvsyncSwitch, Function | SmallTest | Level3)
144 {
145 NodeId nodeId = 0;
146 std::shared_ptr<VsyncStation> vsyncStation = std::make_shared<VsyncStation>(nodeId);
147 ASSERT_NE(vsyncStation, nullptr);
148 vsyncStation->SetUiDvsyncSwitch(true);
149 vsyncStation->SetUiDvsyncSwitch(false);
150 }
151 }
152 } // namespace Rosen
153 } // namespace OHOS