• 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 
16 #include <gtest/gtest.h>
17 #include "vsync_receiver.h"
18 #include "vsync_distributor.h"
19 #include "vsync_controller.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
OnVSync(int64_t now,void * data)26 static void OnVSync(int64_t now, void* data) {}
27 class vsyncReceiverTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31 
32     static inline sptr<VSyncController> vsyncController = nullptr;
33     static inline sptr<VSyncDistributor> vsyncDistributor = nullptr;
34     static inline sptr<VSyncGenerator> vsyncGenerator = nullptr;
35     static inline sptr<VSyncConnection> conn = nullptr;
36     static inline sptr<VSyncReceiver> vsyncReceiver = nullptr;
37 };
38 
SetUpTestCase()39 void vsyncReceiverTest::SetUpTestCase()
40 {
41     vsyncGenerator = CreateVSyncGenerator();
42     vsyncController = new VSyncController(vsyncGenerator, 0);
43     vsyncDistributor = new VSyncDistributor(vsyncController, "vsyncReceiverTest");
44     conn = new VSyncConnection(vsyncDistributor, "vsyncReceiverTest");
45     vsyncReceiver = new VSyncReceiver(conn);
46 }
47 
TearDownTestCase()48 void vsyncReceiverTest::TearDownTestCase()
49 {
50     vsyncReceiver = nullptr;
51     vsyncController = nullptr;
52     vsyncGenerator = nullptr;
53     vsyncDistributor = nullptr;
54     conn = nullptr;
55     DestroyVSyncGenerator();
56 }
57 
58 namespace {
59 /*
60 * Function: Init001
61 * Type: Function
62 * Rank: Important(2)
63 * EnvConditions: N/A
64 * CaseDescription: 1. call Init
65  */
66 HWTEST_F(vsyncReceiverTest, Init001, Function | MediumTest| Level3)
67 {
68     ASSERT_EQ(vsyncReceiverTest::vsyncReceiver->Init(), VSYNC_ERROR_OK);
69 }
70 
71 /*
72 * Function: RequestNextVSync001
73 * Type: Function
74 * Rank: Important(2)
75 * EnvConditions: N/A
76 * CaseDescription: 1. call RequestNextVSync
77  */
78 HWTEST_F(vsyncReceiverTest, RequestNextVSync001, Function | MediumTest| Level3)
79 {
80     VSyncReceiver::FrameCallback fcb = {
81         .userData_ = this,
82         .callback_ = OnVSync,
83     };
84     vsyncDistributor->AddConnection(conn);
85     ASSERT_EQ(vsyncReceiverTest::vsyncReceiver->RequestNextVSync(fcb), VSYNC_ERROR_OK);
86     vsyncDistributor->RemoveConnection(conn);
87 }
88 
89 /*
90 * Function: SetVSyncRate001
91 * Type: Function
92 * Rank: Important(2)
93 * EnvConditions: N/A
94 * CaseDescription: 1. call SetVSyncRate
95  */
96 HWTEST_F(vsyncReceiverTest, SetVSyncRate001, Function | MediumTest| Level3)
97 {
98     VSyncReceiver::FrameCallback fcb = {
99         .userData_ = this,
100         .callback_ = OnVSync,
101     };
102     vsyncDistributor->AddConnection(conn);
103     ASSERT_EQ(vsyncReceiverTest::vsyncReceiver->SetVSyncRate(fcb, 0), VSYNC_ERROR_INVALID_ARGUMENTS);
104     vsyncDistributor->RemoveConnection(conn);
105 }
106 
107 /*
108 * Function: SetVSyncRate002
109 * Type: Function
110 * Rank: Important(2)
111 * EnvConditions: N/A
112 * CaseDescription: 1. call SetVSyncRate
113  */
114 HWTEST_F(vsyncReceiverTest, SetVSyncRate002, Function | MediumTest| Level3)
115 {
116     VSyncReceiver::FrameCallback fcb = {
117         .userData_ = this,
118         .callback_ = OnVSync,
119     };
120     vsyncDistributor->AddConnection(conn);
121     ASSERT_EQ(vsyncReceiverTest::vsyncReceiver->SetVSyncRate(fcb, 1), VSYNC_ERROR_OK);
122     vsyncDistributor->RemoveConnection(conn);
123 }
124 } // namespace
125 } // namespace Rosen
126 } // namespace OHOS