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 };
29
30 class VSyncControllerCallback : public VSyncController::Callback {
31 public:
32 void OnVSyncEvent(int64_t now, int64_t period) override;
33 };
34
SetUpTestCase()35 void VSyncControllerTest::SetUpTestCase()
36 {
37 vsyncGenerator_ = CreateVSyncGenerator();
38 vsyncController_ = new VSyncController(vsyncGenerator_, 0);
39 }
40
TearDownTestCase()41 void VSyncControllerTest::TearDownTestCase()
42 {
43 vsyncController_ = nullptr;
44 vsyncGenerator_ = nullptr;
45 DestroyVSyncGenerator();
46 }
47
OnVSyncEvent(int64_t now,int64_t period)48 void VSyncControllerCallback::OnVSyncEvent(int64_t now, int64_t period) {}
49
50 /*
51 * Function: SetEnable
52 * Type: Function
53 * Rank: Important(2)
54 * EnvConditions: N/A
55 * CaseDescription: 1. call SetEnable
56 */
57 HWTEST_F(VSyncControllerTest, SetEnable001, Function | MediumTest | Level2)
58 {
59 bool isGeneratorEnable = false;
60 ASSERT_EQ(VSyncControllerTest::vsyncController_->SetEnable(true, isGeneratorEnable), VSYNC_ERROR_API_FAILED);
61 }
62
63 /*
64 * Function: SetCallback001
65 * Type: Function
66 * Rank: Important(2)
67 * EnvConditions: N/A
68 * CaseDescription: 1. generate a VSyncControllerCallback obj
69 * 2. call SetCallback
70 */
71 HWTEST_F(VSyncControllerTest, SetCallback001, Function | MediumTest | Level2)
72 {
73 VSyncControllerCallback* callback = new VSyncControllerCallback;
74 ASSERT_EQ(VSyncControllerTest::vsyncController_->SetCallback(callback), VSYNC_ERROR_OK);
75 delete callback;
76 }
77
78 /*
79 * Function: SetCallback002
80 * Type: Function
81 * Rank: Important(2)
82 * EnvConditions: N/A
83 * CaseDescription: 1. call SetCallback with nullptr
84 */
85 HWTEST_F(VSyncControllerTest, SetCallback002, Function | MediumTest | Level2)
86 {
87 ASSERT_EQ(VSyncControllerTest::vsyncController_->SetCallback(nullptr), VSYNC_ERROR_NULLPTR);
88 }
89
90 /*
91 * Function: SetPhaseOffset001
92 * Type: Function
93 * Rank: Important(2)
94 * EnvConditions: N/A
95 * CaseDescription: 1. call SetPhaseOffset
96 */
97 HWTEST_F(VSyncControllerTest, SetPhaseOffset, Function | MediumTest | Level2)
98 {
99 ASSERT_EQ(VSyncControllerTest::vsyncController_->SetPhaseOffset(2), VSYNC_ERROR_INVALID_OPERATING);
100 }
101 }
102