1 /* 2 * Copyright (c) 2023-2024 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 <fcntl.h> 17 #include <gtest/gtest.h> 18 19 #include <cerrno> 20 #include <cstdio> 21 22 #include "event_dump.h" 23 #include "event_log_helper.h" 24 #include "i_input_windows_manager.h" 25 #include "input_device_manager.h" 26 #include "input_event_handler.h" 27 #include "input_manager.h" 28 #include "input_manager_util.h" 29 #include "mouse_event_normalize.h" 30 #include "multimodal_event_handler.h" 31 #include "system_info.h" 32 #include "event_statistic.h" 33 34 #undef MMI_LOG_TAG 35 #define MMI_LOG_TAG "EventDumpTest" 36 37 namespace OHOS { 38 namespace MMI { 39 namespace { 40 using namespace testing::ext; 41 const std::string TEST_FILE_NAME = "/data/log.log"; 42 } // namespace 43 44 class EventDumpTest : public testing::Test { 45 public: SetUp()46 void SetUp() override 47 { 48 fd_ = open(TEST_FILE_NAME.c_str(), O_WRONLY); 49 } 50 TearDown()51 void TearDown() override 52 { 53 close(fd_); 54 fd_ = -1; 55 } 56 57 int32_t fd_; 58 }; 59 60 /** 61 * @tc.name: EventDumpTest_CheckCount_001 62 * @tc.desc: Event dump CheckCount 63 * @tc.type: FUNC 64 * @tc.require: 65 */ 66 HWTEST_F(EventDumpTest, EventDumpTest001, TestSize.Level1) 67 { 68 CALL_TEST_DEBUG; 69 std::vector<std::string> args; 70 int32_t count = 0; 71 MMIEventDump->CheckCount(fd_, args, count); 72 EXPECT_EQ(count, 0); 73 } 74 75 /** 76 * @tc.name: EventDumpTest_CheckCount_002 77 * @tc.desc: Event dump CheckCount 78 * @tc.type: FUNC 79 * @tc.require: 80 */ 81 HWTEST_F(EventDumpTest, EventDumpTest002, TestSize.Level1) 82 { 83 CALL_TEST_DEBUG; 84 std::vector<std::string> args = {"--help"}; 85 int32_t count = 0; 86 MMIEventDump->CheckCount(fd_, args, count); 87 MMIEventDump->ParseCommand(fd_, args); 88 EXPECT_EQ(count, 1); 89 } 90 91 /** 92 * @tc.name: EventDumpTest_CheckCount_003 93 * @tc.desc: Event dump CheckCount 94 * @tc.type: FUNC 95 * @tc.require: 96 */ 97 HWTEST_F(EventDumpTest, EventDumpTest003, TestSize.Level1) 98 { 99 CALL_TEST_DEBUG; 100 std::vector<std::string> args = {"-h"}; 101 int32_t count = 0; 102 MMIEventDump->CheckCount(fd_, args, count); 103 MMIEventDump->ParseCommand(fd_, args); 104 EXPECT_EQ(count, 1); 105 } 106 107 /** 108 * @tc.name: EventDumpTest_CheckCount_004 109 * @tc.desc: Event dump CheckCount 110 * @tc.type: FUNC 111 * @tc.require: 112 */ 113 HWTEST_F(EventDumpTest, EventDumpTest004, TestSize.Level1) 114 { 115 CALL_TEST_DEBUG; 116 std::vector<std::string> args = {"-abc"}; 117 int32_t count = 0; 118 MMIEventDump->CheckCount(fd_, args, count); 119 MMIEventDump->ParseCommand(fd_, args); 120 EXPECT_EQ(count, 3); 121 } 122 123 /** 124 * @tc.name: EventDumpTest_CheckCount_005 125 * @tc.desc: Event dump CheckCount 126 * @tc.type: FUNC 127 * @tc.require: 128 */ 129 HWTEST_F(EventDumpTest, EventDumpTest005, TestSize.Level1) 130 { 131 CALL_TEST_DEBUG; 132 std::vector<std::string> args = {"-a", "--help", "foo", "-bc", "bar"}; 133 int32_t count = 0; 134 MMIEventDump->CheckCount(fd_, args, count); 135 MMIEventDump->ParseCommand(fd_, args); 136 MMIEventDump->DumpEventHelp(fd_, args); 137 EXPECT_EQ(count, 4); 138 } 139 140 /** 141 * @tc.name: EventDumpTest_006 142 * @tc.desc: Event dump InputDeviceManager 143 * @tc.type: FUNC 144 * @tc.require: 145 */ 146 HWTEST_F(EventDumpTest, EventDumpTest006, TestSize.Level1) 147 { 148 CALL_TEST_DEBUG; 149 std::vector<std::string> args = {"-d"}; 150 int32_t count = 0; 151 MMIEventDump->CheckCount(fd_, args, count); 152 MMIEventDump->ParseCommand(fd_, args); 153 ASSERT_NO_FATAL_FAILURE(INPUT_DEV_MGR->Dump(fd_, args)); 154 } 155 156 /** 157 * @tc.name: EventDumpTest_007 158 * @tc.desc: Event dump DeviceList 159 * @tc.type: FUNC 160 * @tc.require: 161 */ 162 HWTEST_F(EventDumpTest, EventDumpTest007, TestSize.Level1) 163 { 164 CALL_TEST_DEBUG; 165 std::vector<std::string> args = {"-l"}; 166 int32_t count = 0; 167 MMIEventDump->CheckCount(fd_, args, count); 168 MMIEventDump->ParseCommand(fd_, args); 169 ASSERT_NO_FATAL_FAILURE(INPUT_DEV_MGR->DumpDeviceList(fd_, args)); 170 } 171 172 /** 173 * @tc.name: EventDumpTest_008 174 * @tc.desc: Event dump WindowsManager 175 * @tc.type: FUNC 176 * @tc.require: 177 */ 178 HWTEST_F(EventDumpTest, EventDumpTest008, TestSize.Level1) 179 { 180 CALL_TEST_DEBUG; 181 std::vector<std::string> args = {"-w"}; 182 int32_t count = 0; 183 MMIEventDump->CheckCount(fd_, args, count); 184 MMIEventDump->ParseCommand(fd_, args); 185 ASSERT_NO_FATAL_FAILURE(WIN_MGR->Dump(fd_, args)); 186 } 187 188 /** 189 * @tc.name: EventDumpTest_009 190 * @tc.desc: Event dump UDSServer 191 * @tc.type: FUNC 192 * @tc.require: 193 */ 194 HWTEST_F(EventDumpTest, EventDumpTest009, TestSize.Level1) 195 { 196 CALL_TEST_DEBUG; 197 std::vector<std::string> args = {"-u"}; 198 int32_t count = 0; 199 auto udsServer = InputHandler->GetUDSServer(); 200 CHKPV(udsServer); 201 MMIEventDump->CheckCount(fd_, args, count); 202 MMIEventDump->ParseCommand(fd_, args); 203 ASSERT_NO_FATAL_FAILURE(udsServer->Dump(fd_, args)); 204 } 205 206 /** 207 * @tc.name: EventDumpTest_010 208 * @tc.desc: Event dump SubscriberHandler 209 * @tc.type: FUNC 210 * @tc.require: 211 */ 212 HWTEST_F(EventDumpTest, EventDumpTest010, TestSize.Level1) 213 { 214 CALL_TEST_DEBUG; 215 std::vector<std::string> args = {"-s"}; 216 int32_t count = 0; 217 auto subscriberHandler = InputHandler->GetSubscriberHandler(); 218 CHKPV(subscriberHandler); 219 MMIEventDump->CheckCount(fd_, args, count); 220 MMIEventDump->ParseCommand(fd_, args); 221 ASSERT_NO_FATAL_FAILURE(subscriberHandler->Dump(fd_, args)); 222 } 223 224 /** 225 * @tc.name: EventDumpTest_011 226 * @tc.desc: Event dump MonitorHandler 227 * @tc.type: FUNC 228 * @tc.require: 229 */ 230 HWTEST_F(EventDumpTest, EventDumpTest011, TestSize.Level1) 231 { 232 CALL_TEST_DEBUG; 233 std::vector<std::string> args = {"-o"}; 234 int32_t count = 0; 235 auto monitorHandler = InputHandler->GetMonitorHandler(); 236 CHKPV(monitorHandler); 237 MMIEventDump->CheckCount(fd_, args, count); 238 MMIEventDump->ParseCommand(fd_, args); 239 ASSERT_NO_FATAL_FAILURE(monitorHandler->Dump(fd_, args)); 240 } 241 242 /** 243 * @tc.name: EventDumpTest_012 244 * @tc.desc: Event dump InterceptorHandler 245 * @tc.type: FUNC 246 * @tc.require: 247 */ 248 HWTEST_F(EventDumpTest, EventDumpTest012, TestSize.Level1) 249 { 250 CALL_TEST_DEBUG; 251 std::vector<std::string> args = {"-i"}; 252 int32_t count = 0; 253 auto interceptorHandler = InputHandler->GetInterceptorHandler(); 254 CHKPV(interceptorHandler); 255 MMIEventDump->CheckCount(fd_, args, count); 256 MMIEventDump->ParseCommand(fd_, args); 257 ASSERT_NO_FATAL_FAILURE(interceptorHandler->Dump(fd_, args)); 258 } 259 260 /** 261 * @tc.name: EventDumpTest_013 262 * @tc.desc: Event dump FilterHandler 263 * @tc.type: FUNC 264 * @tc.require: 265 */ 266 HWTEST_F(EventDumpTest, EventDumpTest013, TestSize.Level1) 267 { 268 CALL_TEST_DEBUG; 269 std::vector<std::string> args = {"-f"}; 270 int32_t count = 0; 271 auto filterHandler = InputHandler->GetFilterHandler(); 272 CHKPV(filterHandler); 273 MMIEventDump->CheckCount(fd_, args, count); 274 MMIEventDump->ParseCommand(fd_, args); 275 ASSERT_NO_FATAL_FAILURE(filterHandler->Dump(fd_, args)); 276 } 277 278 /** 279 * @tc.name: EventDumpTest_014 280 * @tc.desc: Event dump MouseEventHandler 281 * @tc.type: FUNC 282 * @tc.require: 283 */ 284 HWTEST_F(EventDumpTest, EventDumpTest014, TestSize.Level1) 285 { 286 CALL_TEST_DEBUG; 287 std::vector<std::string> args = {"-m"}; 288 int32_t count = 0; 289 MMIEventDump->CheckCount(fd_, args, count); 290 MMIEventDump->ParseCommand(fd_, args); 291 ASSERT_NO_FATAL_FAILURE(MouseEventHdr->Dump(fd_, args)); 292 } 293 294 /** 295 * @tc.name: EventDumpTest_015 296 * @tc.desc: Event dump event 297 * @tc.type: FUNC 298 * @tc.require: 299 */ 300 HWTEST_F(EventDumpTest, EventDumpTest015, TestSize.Level1) 301 { 302 CALL_TEST_DEBUG; 303 std::vector<std::string> args = {"-e"}; 304 int32_t count = 0; 305 MMIEventDump->CheckCount(fd_, args, count); 306 MMIEventDump->ParseCommand(fd_, args); 307 ASSERT_NO_FATAL_FAILURE(EventStatistic::Dump(fd_, args)); 308 } 309 } // namespace MMI 310 } // namespace OHOS