• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
18 #include <fstream>
19 #include "define_multimodal.h"
20 #include "dfx_hisysevent.h"
21 #include "mmi_log.h"
22 
23 namespace OHOS {
24 namespace MMI {
25 namespace {
26 using namespace testing::ext;
27 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "DfxHisysEventTest" };
28 } // namespace
29 
30 class DfxHisysEventTest : public testing::Test {
31 public:
SetUpTestCase(void)32     static void SetUpTestCase(void) {}
TearDownTestCase(void)33     static void TearDownTestCase(void) {}
34 };
35 
36 /**
37  * @tc.name: DfxHisysEventTest_OnClientConnectTest_001
38  * @tc.desc: OnClientConnect
39  * @tc.type: FUNC
40  * @tc.require:
41  */
42 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_OnClientConnectTest_001, TestSize.Level1)
43 {
44     OHOS::HiviewDFX::HiSysEvent::EventType type = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
45     DfxHisysevent::ClientConnectData data;
46     data.pid = 100;
47     int32_t res = 100;
48     DfxHisysevent::OnClientConnect(data, type);
49     type = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
50     DfxHisysevent::OnClientConnect(data, type);
51     EXPECT_EQ(data.pid, res);
52 }
53 
54 /**
55  * @tc.name: DfxHisysEventTest_StatisticTouchpadGestureTest_001
56  * @tc.desc: StatisticTouchpadGesture
57  * @tc.type: FUNC
58  * @tc.require:
59  */
60 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_StatisticTouchpadGestureTest_001, TestSize.Level1)
61 {
62     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
63     CHKPV(pointerEvent);
64     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_BEGIN);
65     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::StatisticTouchpadGesture(pointerEvent));
66     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_BEGIN);
67     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::StatisticTouchpadGesture(pointerEvent));
68     pointerEvent = nullptr;
69     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::StatisticTouchpadGesture(pointerEvent));
70 }
71 
72 /**
73  * @tc.name: DfxHisysEventTest_ReportPowerInfoTest_001
74  * @tc.desc: ReportPowerInfo
75  * @tc.type: FUNC
76  * @tc.require:
77  */
78 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_ReportPowerInfoTest_001, TestSize.Level1)
79 {
80     auto keyEvent = KeyEvent::Create();
81     CHKPV(keyEvent);
82     OHOS::HiviewDFX::HiSysEvent::EventType type = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
83     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
84     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::ReportPowerInfo(keyEvent, type));
85     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
86     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::ReportPowerInfo(keyEvent, type));
87     keyEvent = nullptr;
88     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::ReportPowerInfo(keyEvent, type));
89 }
90 
91 /**
92  * @tc.name: DfxHisysEventTest_OnUpdateTargetPointerTest_001
93  * @tc.desc: OnUpdateTargetPointer
94  * @tc.type: FUNC
95  * @tc.require:
96  */
97 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_OnUpdateTargetPointerTest_001, TestSize.Level1)
98 {
99     std::shared_ptr<PointerEvent> pointer = PointerEvent::Create();
100     CHKPV(pointer);
101     int32_t fd = 1;
102     OHOS::HiviewDFX::HiSysEvent::EventType type = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
103     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::OnUpdateTargetPointer(pointer, fd, type));
104     type = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
105     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::OnUpdateTargetPointer(pointer, fd, type));
106 }
107 
108 /**
109  * @tc.name: DfxHisysEventTest_OnUpdateTargetKeyTest_001
110  * @tc.desc: OnUpdateTargetPointer
111  * @tc.type: FUNC
112  * @tc.require:
113  */
114 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_OnUpdateTargetKeyTest_001, TestSize.Level1)
115 {
116     auto keyEvent = KeyEvent::Create();
117     CHKPV(keyEvent);
118     int32_t fd = 1;
119     OHOS::HiviewDFX::HiSysEvent::EventType type = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
120     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::OnUpdateTargetKey(keyEvent, fd, type));
121     type = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
122     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::OnUpdateTargetKey(keyEvent, fd, type));
123 }
124 
125 /**
126  * @tc.name: DfxHisysEventTest_OnDeviceConnectTest_001
127  * @tc.desc: OnDeviceConnect
128  * @tc.type: FUNC
129  * @tc.require:
130  */
131 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_OnDeviceConnectTest_001, TestSize.Level1)
132 {
133     int32_t id = 1;
134     OHOS::HiviewDFX::HiSysEvent::EventType type = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
135     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::OnDeviceConnect(id, type));
136     type = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
137     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::OnDeviceConnect(id, type));
138     id = INT32_MAX;
139     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::OnDeviceConnect(id, type));
140 }
141 
142 /**
143  * @tc.name: DfxHisysEventTest_OnDeviceDisconnectTest_001
144  * @tc.desc: OnDeviceDisconnect
145  * @tc.type: FUNC
146  * @tc.require:
147  */
148 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_OnDeviceDisconnectTest_001, TestSize.Level1)
149 {
150     OHOS::HiviewDFX::HiSysEvent::EventType type = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
151     int32_t id = -1;
152     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::OnDeviceDisconnect(id, type));
153     id = 1;
154     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::OnDeviceDisconnect(id, type));
155 }
156 
157 /**
158  * @tc.name: DfxHisysEventTest_OnLidSwitchChangedTest_001
159  * @tc.desc: OnLidSwitchChanged
160  * @tc.type: FUNC
161  * @tc.require:
162  */
163 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_OnLidSwitchChangedTest_001, TestSize.Level1)
164 {
165     int32_t lidSwitch = 0;
166     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::OnLidSwitchChanged(lidSwitch));
167 }
168 
169 /**
170  * @tc.name: DfxHisysEventTest_CalcKeyDispTimesTest_001
171  * @tc.desc: CalcKeyDispTimes
172  * @tc.type: FUNC
173  * @tc.require:
174  */
175 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_CalcKeyDispTimesTest_001, TestSize.Level1)
176 {
177     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::CalcKeyDispTimes());
178 }
179 
180 /**
181  * @tc.name: DfxHisysEventTest_CalcPointerDispTimesTest_001
182  * @tc.desc: CalcPointerDispTimes
183  * @tc.type: FUNC
184  * @tc.require:
185  */
186 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_CalcPointerDispTimesTest_001, TestSize.Level1)
187 {
188     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::CalcPointerDispTimes());
189 }
190 
191 /**
192  * @tc.name: DfxHisysEventTest_ReportDispTimesTest_001
193  * @tc.desc: ReportDispTimes
194  * @tc.type: FUNC
195  * @tc.require:
196  */
197 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_ReportDispTimesTest_001, TestSize.Level1)
198 {
199     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::ReportDispTimes());
200 }
201 
202 /**
203  * @tc.name: DfxHisysEventTest_ReportFailIfInvalidTimeTest_001
204  * @tc.desc: ReportFailIfInvalidTime
205  * @tc.type: FUNC
206  * @tc.require:
207  */
208 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_ReportFailIfInvalidTimeTest_001, TestSize.Level1)
209 {
210     int32_t intervalTime = 1000;
211     auto pointerEvent = PointerEvent::Create();
212     CHKPV(pointerEvent);
213     PointerEvent::PointerItem item;
214     item.SetPointerId(0);
215     item.SetDeviceId(1);
216     pointerEvent->AddPointerItem(item);
217     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::ReportFailIfInvalidTime(pointerEvent, intervalTime));
218 
219     item.SetPointerId(1);
220     item.SetDeviceId(1);
221     pointerEvent->AddPointerItem(item);
222     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::ReportFailIfInvalidTime(pointerEvent, intervalTime));
223 }
224 
225 /**
226  * @tc.name: DfxHisysEventTest_ReportFailIfInvalidDistanceTest_001
227  * @tc.desc: ReportFailIfInvalidDistance
228  * @tc.type: FUNC
229  * @tc.require:
230  */
231 HWTEST_F(DfxHisysEventTest, DfxHisysEventTest_ReportFailIfInvalidDistanceTest_001, TestSize.Level1)
232 {
233     auto pointerEvent = PointerEvent::Create();
234     CHKPV(pointerEvent);
235     float distance = 10;
236     ASSERT_NO_FATAL_FAILURE(DfxHisysevent::ReportFailIfInvalidDistance(pointerEvent, distance));
237 }
238 } // namespace MMI
239 } // namespace OHOS