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) 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)48 void VSyncControllerCallback::OnVSyncEvent(int64_t now) {}
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 ASSERT_EQ(VSyncControllerTest::vsyncController_->SetEnable(true), VSYNC_ERROR_OK);
60 }
61
62 /*
63 * Function: SetCallback001
64 * Type: Function
65 * Rank: Important(2)
66 * EnvConditions: N/A
67 * CaseDescription: 1. generate a VSyncControllerCallback obj
68 * 2. call SetCallback
69 */
70 HWTEST_F(VSyncControllerTest, SetCallback001, Function | MediumTest | Level2)
71 {
72 VSyncControllerCallback* callback = new VSyncControllerCallback;
73 ASSERT_EQ(VSyncControllerTest::vsyncController_->SetCallback(callback), VSYNC_ERROR_OK);
74 delete callback;
75 }
76
77 /*
78 * Function: SetCallback002
79 * Type: Function
80 * Rank: Important(2)
81 * EnvConditions: N/A
82 * CaseDescription: 1. call SetCallback with nullptr
83 */
84 HWTEST_F(VSyncControllerTest, SetCallback002, Function | MediumTest | Level2)
85 {
86 ASSERT_EQ(VSyncControllerTest::vsyncController_->SetCallback(nullptr), VSYNC_ERROR_NULLPTR);
87 }
88
89 /*
90 * Function: SetPhaseOffset001
91 * Type: Function
92 * Rank: Important(2)
93 * EnvConditions: N/A
94 * CaseDescription: 1. call SetPhaseOffset
95 */
96 HWTEST_F(VSyncControllerTest, SetPhaseOffset, Function | MediumTest | Level2)
97 {
98 ASSERT_EQ(VSyncControllerTest::vsyncController_->SetPhaseOffset(2), VSYNC_ERROR_OK);
99 }
100 }
101