1 /* 2 * Copyright (c) 2021-2022 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 "input_manager.h" 18 #include "input_manager_command.h" 19 20 namespace OHOS { 21 namespace MMI { 22 namespace { 23 using namespace testing::ext; 24 constexpr int32_t KNUCKLE_SIZE = 9; 25 } // namespace 26 class InjectEventTest : public testing::Test { 27 public: SetUpTestCase(void)28 static void SetUpTestCase(void) {} TearDownTestCase(void)29 static void TearDownTestCase(void) {} 30 }; 31 32 /** 33 * @tc.name:InjectEvent_InjectMouse_001 34 * @tc.desc: test inject mouse move interface 35 * @tc.type: FUNC 36 * @tc.require:AR000GJN3F 37 */ 38 HWTEST_F(InjectEventTest, InjectEvent_InjectMouse_001, TestSize.Level1) 39 { 40 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 41 char command1[] = {"uinput"}; 42 char command2[] = {"-M"}; 43 char command3[] = {"-m"}; 44 char command4[] = {"100"}; 45 char command5[] = {"200"}; 46 char *argv[] = {command1, command2, command3, command4, command5}; 47 int32_t result = inputManagerCommand->ParseCommand(5, argv); 48 EXPECT_EQ(OHOS::ERR_OK, result); 49 } 50 51 /** 52 * @tc.name:InjectEvent_InjectMouse_002 53 * @tc.desc: test inject mouse down interface 54 * @tc.type: FUNC 55 * @tc.require:SR000GGQBJ 56 */ 57 HWTEST_F(InjectEventTest, InjectEvent_InjectMouse_002, TestSize.Level1) 58 { 59 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 60 char command1[] = {"uinput"}; 61 char command2[] = {"-M"}; 62 char command3[] = {"-d"}; 63 char command4[] = {"0"}; 64 char *argv[] = {command1, command2, command3, command4}; 65 int32_t result = inputManagerCommand->ParseCommand(4, argv); 66 EXPECT_EQ(OHOS::ERR_OK, result); 67 } 68 69 /** 70 * @tc.name:InjectEvent_InjectMouse_003 71 * @tc.desc: test inject mouse up interface 72 * @tc.type: FUNC 73 * @tc.require:SR000GGQBJ 74 */ 75 HWTEST_F(InjectEventTest, InjectEvent_InjectMouse_003, TestSize.Level1) 76 { 77 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 78 char command1[] = {"uinput"}; 79 char command2[] = {"-M"}; 80 char command3[] = {"-u"}; 81 char command4[] = {"0"}; 82 char *argv[] = {command1, command2, command3, command4}; 83 int32_t result = inputManagerCommand->ParseCommand(4, argv); 84 EXPECT_EQ(OHOS::ERR_OK, result); 85 } 86 87 /** 88 * @tc.name:InjectEvent_InjectMouse_004 89 * @tc.desc: test inject mouse click interface 90 * @tc.type: FUNC 91 * @tc.require:SR000GGQBJ 92 */ 93 HWTEST_F(InjectEventTest, InjectEvent_InjectMouse_004, TestSize.Level1) 94 { 95 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 96 char command1[] = {"uinput"}; 97 char command2[] = {"-M"}; 98 char command3[] = {"-c"}; 99 char command4[] = {"0"}; 100 char *argv[] = {command1, command2, command3, command4}; 101 int32_t result = inputManagerCommand->ParseCommand(4, argv); 102 EXPECT_EQ(OHOS::ERR_OK, result); 103 } 104 105 /** 106 * @tc.name:InjectEvent_InjectMouse_005 107 * @tc.desc: test inject mouse double click interface 108 * @tc.type: FUNC 109 * @tc.require:SR000GGQBJ 110 */ 111 HWTEST_F(InjectEventTest, InjectEvent_InjectMouse_005, TestSize.Level1) 112 { 113 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 114 char command1[] = {"uinput"}; 115 char command2[] = {"-M"}; 116 char command3[] = {"-b"}; 117 char command4[] = {"200"}; 118 char command5[] = {"1250"}; 119 char command6[] = {"0"}; 120 char command7[] = {"100"}; 121 char command8[] = {"300"}; 122 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8}; 123 int32_t result = inputManagerCommand->ParseCommand(8, argv); 124 EXPECT_EQ(OHOS::ERR_OK, result); 125 } 126 127 /** 128 * @tc.name:InjectEvent_InjectMouse_006 129 * @tc.desc: test inject mouse scroll interface 130 * @tc.type: FUNC 131 * @tc.require:SR000GGQBJ 132 */ 133 HWTEST_F(InjectEventTest, InjectEvent_InjectMouse_006, TestSize.Level1) 134 { 135 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 136 char command1[] = {"uinput"}; 137 char command2[] = {"-M"}; 138 char command3[] = {"-s"}; 139 char command4[] = {"50"}; 140 char *argv[] = {command1, command2, command3, command4}; 141 int32_t result = inputManagerCommand->ParseCommand(4, argv); 142 EXPECT_EQ(OHOS::ERR_OK, result); 143 } 144 145 /** 146 * @tc.name:InjectEvent_InjectMouse_007 147 * @tc.desc: test inject mouse smooth movement interface 148 * @tc.type: FUNC 149 * @tc.require:SR000GGQBJ 150 */ 151 HWTEST_F(InjectEventTest, InjectEvent_InjectMouse_007, TestSize.Level1) 152 { 153 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 154 char command1[] = {"uinput"}; 155 char command2[] = {"-M"}; 156 char command3[] = {"-m"}; 157 char command4[] = {"200"}; 158 char command5[] = {"200"}; 159 char command6[] = {"200"}; 160 char command7[] = {"700"}; 161 char command8[] = {"3000"}; 162 char command9[] = {"--trace"}; 163 164 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8, command9}; 165 int32_t result = inputManagerCommand->ParseCommand(9, argv); 166 EXPECT_EQ(OHOS::ERR_OK, result); 167 } 168 169 /** 170 * @tc.name:InjectEvent_InjectMouse_008 171 * @tc.desc: test inject mouse soomth drag interface 172 * @tc.type: FUNC 173 * @tc.require:SR000GGQBJ 174 */ 175 HWTEST_F(InjectEventTest, InjectEvent_InjectMouse_008, TestSize.Level1) 176 { 177 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 178 char command1[] = {"uinput"}; 179 char command2[] = {"-M"}; 180 char command3[] = {"-g"}; 181 char command4[] = {"100"}; 182 char command5[] = {"200"}; 183 char command6[] = {"100"}; 184 char command7[] = {"700"}; 185 char command8[] = {"3000"}; 186 187 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8}; 188 int32_t result = inputManagerCommand->ParseCommand(8, argv); 189 EXPECT_EQ(OHOS::ERR_OK, result); 190 } 191 192 /** 193 * @tc.name:InjectEvent_InjectKey_001 194 * @tc.desc: test inject key down interface 195 * @tc.type: FUNC 196 * @tc.require:SR000GGQBJ 197 */ 198 HWTEST_F(InjectEventTest, InjectEvent_InjectKey_001, TestSize.Level1) 199 { 200 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 201 char command1[] = {"uinput"}; 202 char command2[] = {"-K"}; 203 char command3[] = {"-d"}; 204 char command4[] = {"16"}; 205 char *argv[] = {command1, command2, command3, command4}; 206 int32_t result = inputManagerCommand->ParseCommand(4, argv); 207 EXPECT_EQ(OHOS::ERR_OK, result); 208 } 209 210 /** 211 * @tc.name:InjectEvent_InjectKey_002 212 * @tc.desc: test inject key up interface 213 * @tc.type: FUNC 214 * @tc.require:SR000GGQBJ 215 */ 216 HWTEST_F(InjectEventTest, InjectEvent_InjectKey_002, TestSize.Level1) 217 { 218 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 219 char command1[] = {"uinput"}; 220 char command2[] = {"-K"}; 221 char command3[] = {"-d"}; 222 char command4[] = {"16"}; 223 char command5[] = {"-i"}; 224 char command6[] = {"1000"}; 225 char command7[] = {"-u"}; 226 char command8[] = {"16"}; 227 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8}; 228 int32_t result = inputManagerCommand->ParseCommand(8, argv); 229 EXPECT_EQ(OHOS::ERR_OK, result); 230 } 231 232 /** 233 * @tc.name:InjectEvent_InjectKey_003 234 * @tc.desc: test inject press and hold the key interface 235 * @tc.type: FUNC 236 * @tc.require:SR000GGQBJ 237 */ 238 HWTEST_F(InjectEventTest, InjectEvent_InjectKey_003, TestSize.Level1) 239 { 240 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 241 char command1[] = {"uinput"}; 242 char command2[] = {"-K"}; 243 char command3[] = {"-l"}; 244 char command4[] = {"17"}; 245 char *argv[] = {command1, command2, command3, command4}; 246 int32_t result = inputManagerCommand->ParseCommand(4, argv); 247 EXPECT_EQ(OHOS::ERR_OK, result); 248 } 249 250 /** 251 * @tc.name:InjectEvent_InjectTouch_001 252 * @tc.desc: test inject touch screen smooth movement interface 253 * @tc.type: FUNC 254 * @tc.require:SR000GGQBJ 255 */ 256 HWTEST_F(InjectEventTest, InjectEvent_InjectTouch_001, TestSize.Level1) 257 { 258 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 259 char command1[] = {"uinput"}; 260 char command2[] = {"-T"}; 261 char command3[] = {"-m"}; 262 char command4[] = {"100"}; 263 char command5[] = {"200"}; 264 char command6[] = {"100"}; 265 char command7[] = {"600"}; 266 char command8[] = {"1000"}; 267 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8}; 268 int32_t result = inputManagerCommand->ParseCommand(8, argv); 269 EXPECT_EQ(OHOS::ERR_OK, result); 270 } 271 272 /** 273 * @tc.name:InjectEvent_InjectTouch_002 274 * @tc.desc: test inject touch down interface 275 * @tc.type: FUNC 276 * @tc.require:SR000GGQBJ 277 */ 278 HWTEST_F(InjectEventTest, InjectEvent_InjectTouch_002, TestSize.Level1) 279 { 280 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 281 char command1[] = {"uinput"}; 282 char command2[] = {"-T"}; 283 char command3[] = {"-d"}; 284 char command4[] = {"100"}; 285 char command5[] = {"200"}; 286 char *argv[] = {command1, command2, command3, command4, command5}; 287 int32_t result = inputManagerCommand->ParseCommand(5, argv); 288 EXPECT_EQ(OHOS::ERR_OK, result); 289 } 290 291 /** 292 * @tc.name:InjectEvent_InjectTouch_003 293 * @tc.desc: test inject touch up interface 294 * @tc.type: FUNC 295 * @tc.require:SR000GGQBJ 296 */ 297 HWTEST_F(InjectEventTest, InjectEvent_InjectTouch_003, TestSize.Level1) 298 { 299 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 300 char command1[] = {"uinput"}; 301 char command2[] = {"-T"}; 302 char command3[] = {"-u"}; 303 char command4[] = {"100"}; 304 char command5[] = {"200"}; 305 char *argv[] = {command1, command2, command3, command4, command5}; 306 int32_t result = inputManagerCommand->ParseCommand(5, argv); 307 EXPECT_EQ(OHOS::ERR_OK, result); 308 } 309 310 /** 311 * @tc.name:InjectEvent_InjectTouch_004 312 * @tc.desc: test inject touch click interface 313 * @tc.type: FUNC 314 * @tc.require:SR000GGQBJ 315 */ 316 HWTEST_F(InjectEventTest, InjectEvent_InjectTouch_004, TestSize.Level1) 317 { 318 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 319 char command1[] = {"uinput"}; 320 char command2[] = {"-T"}; 321 char command3[] = {"-c"}; 322 char command4[] = {"200"}; 323 char command5[] = {"1250"}; 324 char command6[] = {"200"}; 325 char *argv[] = {command1, command2, command3, command4, command5, command6}; 326 int32_t result = inputManagerCommand->ParseCommand(5, argv); 327 EXPECT_EQ(OHOS::ERR_OK, result); 328 } 329 330 /** 331 * @tc.name:InjectEvent_InjectTouch_005 332 * @tc.desc: test inject touch drag interface 333 * @tc.type: FUNC 334 * @tc.require:SR000GGQBJ 335 */ 336 HWTEST_F(InjectEventTest, InjectEvent_InjectTouch_005, TestSize.Level1) 337 { 338 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 339 char command1[] = {"uinput"}; 340 char command2[] = {"-T"}; 341 char command3[] = {"-g"}; 342 char command4[] = {"100"}; 343 char command5[] = {"200"}; 344 char command6[] = {"100"}; 345 char command7[] = {"600"}; 346 char command8[] = {"700"}; 347 char command9[] = {"3000"}; 348 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8, command9}; 349 int32_t result = inputManagerCommand->ParseCommand(9, argv); 350 EXPECT_EQ(OHOS::ERR_OK, result); 351 } 352 353 /** 354 * @tc.name:InjectEvent_InjectKnuckle_001 355 * @tc.desc: test inject single knuckle double click interface 356 * @tc.type: FUNC 357 * @tc.require: 358 */ 359 HWTEST_F(InjectEventTest, InjectEvent_InjectKnuckle_001, TestSize.Level1) 360 { 361 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 362 char command1[] = {"uinput"}; 363 char command2[] = {"-T"}; 364 char command3[] = {"-k"}; 365 char command4[] = {"-s"}; 366 char command5[] = {"100"}; 367 char command6[] = {"200"}; 368 char command7[] = {"130"}; 369 char command8[] = {"230"}; 370 char command9[] = {"200"}; 371 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8, command9}; 372 int32_t result = inputManagerCommand->ParseCommand(KNUCKLE_SIZE, argv); 373 EXPECT_EQ(OHOS::ERR_OK, result); 374 } 375 376 /** 377 * @tc.name:InjectEvent_InjectKnuckle_002 378 * @tc.desc: test inject double knuckle double click interface 379 * @tc.type: FUNC 380 * @tc.require: 381 */ 382 HWTEST_F(InjectEventTest, InjectEvent_InjectKnuckle_002, TestSize.Level1) 383 { 384 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 385 char command1[] = {"uinput"}; 386 char command2[] = {"-T"}; 387 char command3[] = {"-k"}; 388 char command4[] = {"-d"}; 389 char command5[] = {"200"}; 390 char command6[] = {"300"}; 391 char command7[] = {"230"}; 392 char command8[] = {"330"}; 393 char command9[] = {"200"}; 394 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8, command9}; 395 int32_t result = inputManagerCommand->ParseCommand(KNUCKLE_SIZE, argv); 396 EXPECT_EQ(OHOS::ERR_OK, result); 397 } 398 } // namespace MMI 399 } // namespace OHOS