• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_controller.h>
17 
18 using namespace testing;
19 using namespace testing::ext;
20 
21 namespace OHOS::Rosen {
22 class VSyncControllerTest : public testing::Test {
23 public:
24     static void SetUpTestCase();
25     static void TearDownTestCase();
26     static inline sptr<VSyncController> vsyncController_ = nullptr;
27     static inline sptr<VSyncGenerator> vsyncGenerator_ = nullptr;
28     static constexpr const int32_t WAIT_SYSTEM_ABILITY_REPORT_DATA_SECONDS = 5;
29 };
30 
31 class VSyncControllerCallback : public VSyncController::Callback {
32 public:
33     void OnVSyncEvent(int64_t now, int64_t period,
34         uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) override;
35     void OnDVSyncEvent(int64_t now, int64_t period,
36         uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) override;
37     void OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates) override;
38 };
39 
SetUpTestCase()40 void VSyncControllerTest::SetUpTestCase()
41 {
42     vsyncGenerator_ = CreateVSyncGenerator();
43     vsyncController_ = new VSyncController(vsyncGenerator_, 0);
44 }
45 
TearDownTestCase()46 void VSyncControllerTest::TearDownTestCase()
47 {
48     sleep(WAIT_SYSTEM_ABILITY_REPORT_DATA_SECONDS);
49     vsyncGenerator_ = nullptr;
50     DestroyVSyncGenerator();
51     vsyncController_ = nullptr;
52 }
53 
OnVSyncEvent(int64_t now,int64_t period,uint32_t refreshRate,VSyncMode vsyncMode,uint32_t vsyncMaxRefreshRate)54 void VSyncControllerCallback::OnVSyncEvent(int64_t now, int64_t period,
55     uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) {}
OnDVSyncEvent(int64_t now,int64_t period,uint32_t refreshRate,VSyncMode vsyncMode,uint32_t vsyncMaxRefreshRate)56 void VSyncControllerCallback::OnDVSyncEvent(int64_t now, int64_t period,
57     uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) {}
58 
OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t,uint32_t>> & refreshRates)59 void VSyncControllerCallback::OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates)
60 {
61 }
62 
63 /*
64 * Function: SetEnable
65 * Type: Function
66 * Rank: Important(2)
67 * EnvConditions: N/A
68 * CaseDescription: 1. call SetEnable
69  */
70 HWTEST_F(VSyncControllerTest, SetEnable001, Function | MediumTest | Level2)
71 {
72     bool vsyncEnabledFlag = false;
73     ASSERT_EQ(VSyncControllerTest::vsyncController_->SetEnable(true, vsyncEnabledFlag), VSYNC_ERROR_OK);
74     ASSERT_EQ(vsyncEnabledFlag, true);
75 }
76 
77 /*
78 * Function: SetCallback001
79 * Type: Function
80 * Rank: Important(2)
81 * EnvConditions: N/A
82 * CaseDescription: 1. generate a VSyncControllerCallback obj
83 *                  2. call SetCallback
84  */
85 HWTEST_F(VSyncControllerTest, SetCallback001, Function | MediumTest | Level2)
86 {
87     VSyncControllerCallback* callback = new VSyncControllerCallback;
88     ASSERT_EQ(VSyncControllerTest::vsyncController_->SetCallback(callback), VSYNC_ERROR_OK);
89     delete callback;
90 }
91 
92 /*
93 * Function: SetCallback002
94 * Type: Function
95 * Rank: Important(2)
96 * EnvConditions: N/A
97 * CaseDescription: 1. call SetCallback with nullptr
98  */
99 HWTEST_F(VSyncControllerTest, SetCallback002, Function | MediumTest | Level2)
100 {
101     ASSERT_EQ(VSyncControllerTest::vsyncController_->SetCallback(nullptr), VSYNC_ERROR_NULLPTR);
102 }
103 
104 /*
105 * Function: SetPhaseOffset001
106 * Type: Function
107 * Rank: Important(2)
108 * EnvConditions: N/A
109 * CaseDescription: 1. call SetPhaseOffset
110  */
111 HWTEST_F(VSyncControllerTest, SetPhaseOffset001, Function | MediumTest | Level2)
112 {
113     ASSERT_EQ(VSyncControllerTest::vsyncController_->SetPhaseOffset(2), VSYNC_ERROR_OK);
114 }
115 
116 /*
117 * Function: SetEnable002
118 * Type: Function
119 * Rank: Important(2)
120 * EnvConditions: N/A
121 * CaseDescription: 1. call SetEnable
122  */
123 HWTEST_F(VSyncControllerTest, SetEnable002, Function | MediumTest | Level2)
124 {
125     bool vsyncEnabledFlag = true;
126     ASSERT_EQ(VSyncControllerTest::vsyncController_->SetEnable(false, vsyncEnabledFlag), VSYNC_ERROR_OK);
127     ASSERT_EQ(vsyncEnabledFlag, false);
128 }
129 
130 /*
131 * Function: SetPhaseOffset002
132 * Type: Function
133 * Rank: Important(2)
134 * EnvConditions: N/A
135 * CaseDescription: 1. call SetPhaseOffset
136  */
137 HWTEST_F(VSyncControllerTest, SetPhaseOffset002, Function | MediumTest | Level2)
138 {
139     ASSERT_EQ(VSyncControllerTest::vsyncController_->SetPhaseOffset(2), VSYNC_ERROR_INVALID_OPERATING);
140 }
141 }
142