• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "client_msg_handler.h"
18 #include "input_active_subscribe_manager.h"
19 #include "input_handler_type.h"
20 #include "mmi_log.h"
21 
22 #undef MMI_LOG_TAG
23 #define MMI_LOG_TAG "ClientMsgHandlerTest"
24 
25 
26 namespace OHOS {
27 namespace MMI {
28 namespace {
29 using namespace testing::ext;
30 } // namespace
31 
32 class MockUDSClient : public UDSClient {
33 public:
Socket()34     int32_t Socket() override { return 0; }
35 };
36 
37 class ClientMsgHandlerTest : public testing::Test {
38 public:
SetUpTestCase(void)39     static void SetUpTestCase(void)
40     {}
TearDownTestCase(void)41     static void TearDownTestCase(void)
42     {}
43 };
44 
45 /**
46  * @tc.name: ClientMsgHandler_Test_001
47  * @tc.desc: Test ClientMsgHandler
48  * @tc.type: FUNC
49  * @tc.require:
50  */
51 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_001, TestSize.Level1)
52 {
53     CALL_TEST_DEBUG;
54     ClientMsgHandler handler;
55     const MockUDSClient client;
56     NetPacket pkt(MmiMessageId::ON_KEY_EVENT);
57     int32_t result = handler.OnPreKeyEvent(client, pkt);
58     EXPECT_EQ(result, SHIELD_MODE::UNSET_MODE);
59 }
60 
61 
62 /**
63  * @tc.name: ClientMsgHandler_Test_002
64  * @tc.desc: Test ClientMsgHandler
65  * @tc.type: FUNC
66  * @tc.require:
67  */
68 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_002, TestSize.Level1)
69 {
70     CALL_TEST_DEBUG;
71     ClientMsgHandler handler;
72     MockUDSClient client;
73     NetPacket pkt(MmiMessageId::ON_KEY_EVENT);
74     int32_t result = handler.NotifyBundleName(client, pkt);
75     EXPECT_EQ(result, SHIELD_MODE::FACTORY_MODE);
76 }
77 
78 /**
79  * @tc.name: ClientMsgHandler_Test_003
80  * @tc.desc: Test ClientMsgHandler
81  * @tc.type: FUNC
82  * @tc.require:
83  */
84 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_003, TestSize.Level1)
85 {
86     CALL_TEST_DEBUG;
87     ClientMsgHandler handler;
88     MockUDSClient client;
89     NetPacket pkt(MmiMessageId::ON_KEY_EVENT);
90     int32_t result = handler.ReportDeviceConsumer(client, pkt);
91     EXPECT_EQ(result, SHIELD_MODE::UNSET_MODE);
92 }
93 
94 /**
95  * @tc.name: ClientMsgHandler_Test_004
96  * @tc.desc: Test ClientMsgHandler
97  * @tc.type: FUNC
98  * @tc.require:
99  */
100 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_004, TestSize.Level1)
101 {
102     CALL_TEST_DEBUG;
103     ClientMsgHandler handler;
104     MockUDSClient client;
105     NetPacket pkt(MmiMessageId::ON_KEY_EVENT);
106     int32_t result = handler.OnSubscribeKeyMonitor(client, pkt);
107     EXPECT_EQ(result, SHIELD_MODE::UNSET_MODE);
108 }
109 
110 /**
111  * @tc.name: ClientMsgHandler_Test_005
112  * @tc.desc: Test ClientMsgHandler
113  * @tc.type: FUNC
114  * @tc.require:
115  */
116 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_005, TestSize.Level1)
117 {
118     CALL_TEST_DEBUG;
119     ClientMsgHandler handler;
120     MockUDSClient client;
121     NetPacket pkt(MmiMessageId::ON_KEY_EVENT);
122     int32_t result = handler.NotifyWindowStateError(client, pkt);
123     EXPECT_EQ(result, SHIELD_MODE::UNSET_MODE);
124 }
125 
126 /**
127  * @tc.name: ClientMsgHandler_Test_006
128  * @tc.desc: Test ClientMsgHandler
129  * @tc.type: FUNC
130  * @tc.require:
131  */
132 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_006, TestSize.Level1)
133 {
134     CALL_TEST_DEBUG;
135     ClientMsgHandler handler;
136     int32_t eventId = 1;
137     int64_t actionTime = 2;
138     ASSERT_NO_FATAL_FAILURE(handler.OnDispatchEventProcessed(eventId, actionTime));
139     eventId = -1;
140     actionTime = -2;
141     ASSERT_NO_FATAL_FAILURE(handler.OnDispatchEventProcessed(eventId, actionTime));
142 }
143 
144 /**
145  * @tc.name: ClientMsgHandler_Test_007
146  * @tc.desc: Test ClientMsgHandler
147  * @tc.type: FUNC
148  * @tc.require:
149  */
150 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_007, TestSize.Level1)
151 {
152     CALL_TEST_DEBUG;
153     ClientMsgHandler handler;
154     MockUDSClient client;
155     NetPacket pkt(MmiMessageId::ON_KEY_EVENT);
156     int32_t result = handler.OnSubscribeInputActiveCallback(client, pkt);
157     EXPECT_EQ(result, SHIELD_MODE::UNSET_MODE);
158 }
159 
160 /**
161  * @tc.name: ClientMsgHandler_Test_008
162  * @tc.desc: Test ClientMsgHandler
163  * @tc.type: FUNC
164  * @tc.require:
165  */
166 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_008, TestSize.Level1)
167 {
168     CALL_TEST_DEBUG;
169     ClientMsgHandler handler;
170     MockUDSClient client;
171     NetPacket pkt(MmiMessageId::ON_KEY_EVENT);
172     int32_t result = handler.OnSubscribeLongPressEventCallback(client, pkt);
173     EXPECT_EQ(result, SHIELD_MODE::UNSET_MODE);
174 }
175 
176 /**
177  * @tc.name: ClientMsgHandler_Test_009
178  * @tc.desc: Test ClientMsgHandler
179  * @tc.type: FUNC
180  * @tc.require:
181  */
182 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_009, TestSize.Level1)
183 {
184     CALL_TEST_DEBUG;
185     ClientMsgHandler handler;
186     MockUDSClient client;
187     NetPacket pkt(MmiMessageId::ON_KEY_EVENT);
188     int32_t result = handler.OnSubscribeTabletProximityCallback(client, pkt);
189     EXPECT_NE(result, PACKET_READ_FAIL);
190 }
191 
192 /**
193  * @tc.name: ClientMsgHandler_Test_010
194  * @tc.desc: Test ClientMsgHandler
195  * @tc.type: FUNC
196  * @tc.require:
197  */
198 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_010, TestSize.Level1)
199 {
200     CALL_TEST_DEBUG;
201     ClientMsgHandler handler;
202     MockUDSClient client;
203     NetPacket pkt(MmiMessageId::ON_KEY_EVENT);
204     int32_t result = handler.OnAnr(client, pkt);
205     EXPECT_EQ(result, SHIELD_MODE::UNSET_MODE);
206 }
207 
208 /**
209  * @tc.name: ClientMsgHandler_Test_011
210  * @tc.desc: Test ClientMsgHandler
211  * @tc.type: FUNC
212  * @tc.require:
213  */
214 HWTEST_F(ClientMsgHandlerTest, ClientMsgHandler_Test_011, TestSize.Level1)
215 {
216     CALL_TEST_DEBUG;
217     ClientMsgHandler handler;
218     MockUDSClient client;
219     NetPacket pkt(MmiMessageId::ON_KEY_EVENT);
220     int32_t result = handler.OnAnr(client, pkt);
221     EXPECT_EQ(result, SHIELD_MODE::UNSET_MODE);
222 }
223 } // namespace MMI
224 } // namespace OHOS