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 using namespace OHOS::MMI; 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 soomth 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_InjectKey_001 171 * @tc.desc: test inject key down interface 172 * @tc.type: FUNC 173 * @tc.require:SR000GGQBJ 174 */ 175 HWTEST_F(InjectEventTest, InjectEvent_InjectKey_001, TestSize.Level1) 176 { 177 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 178 char command1[] = {"uinput"}; 179 char command2[] = {"-K"}; 180 char command3[] = {"-d"}; 181 char command4[] = {"16"}; 182 char *argv[] = {command1, command2, command3, command4}; 183 int32_t result = inputManagerCommand->ParseCommand(4, argv); 184 EXPECT_EQ(OHOS::ERR_OK, result); 185 } 186 187 /** 188 * @tc.name:InjectEvent_InjectKey_002 189 * @tc.desc: test inject key up interface 190 * @tc.type: FUNC 191 * @tc.require:SR000GGQBJ 192 */ 193 HWTEST_F(InjectEventTest, InjectEvent_InjectKey_002, TestSize.Level1) 194 { 195 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 196 char command1[] = {"uinput"}; 197 char command2[] = {"-K"}; 198 char command3[] = {"-d"}; 199 char command4[] = {"16"}; 200 char command5[] = {"-i"}; 201 char command6[] = {"1000"}; 202 char command7[] = {"-u"}; 203 char command8[] = {"16"}; 204 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8}; 205 int32_t result = inputManagerCommand->ParseCommand(8, argv); 206 EXPECT_EQ(OHOS::ERR_OK, result); 207 } 208 209 /** 210 * @tc.name:InjectEvent_InjectKey_003 211 * @tc.desc: test inject press and hold the key interface 212 * @tc.type: FUNC 213 * @tc.require:SR000GGQBJ 214 */ 215 HWTEST_F(InjectEventTest, InjectEvent_InjectKey_003, TestSize.Level1) 216 { 217 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 218 char command1[] = {"uinput"}; 219 char command2[] = {"-K"}; 220 char command3[] = {"-l"}; 221 char command4[] = {"17"}; 222 char *argv[] = {command1, command2, command3, command4}; 223 int32_t result = inputManagerCommand->ParseCommand(4, argv); 224 EXPECT_EQ(OHOS::ERR_OK, result); 225 } 226 227 /** 228 * @tc.name:InjectEvent_InjectTouch_001 229 * @tc.desc: test inject touch screen smooth movement interface 230 * @tc.type: FUNC 231 * @tc.require:SR000GGQBJ 232 */ 233 HWTEST_F(InjectEventTest, InjectEvent_InjectTouch_001, TestSize.Level1) 234 { 235 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 236 char command1[] = {"uinput"}; 237 char command2[] = {"-T"}; 238 char command3[] = {"-m"}; 239 char command4[] = {"100"}; 240 char command5[] = {"200"}; 241 char command6[] = {"100"}; 242 char command7[] = {"600"}; 243 char command8[] = {"1000"}; 244 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8}; 245 int32_t result = inputManagerCommand->ParseCommand(8, argv); 246 EXPECT_EQ(OHOS::ERR_OK, result); 247 } 248 249 /** 250 * @tc.name:InjectEvent_InjectTouch_002 251 * @tc.desc: test inject touch down interface 252 * @tc.type: FUNC 253 * @tc.require:SR000GGQBJ 254 */ 255 HWTEST_F(InjectEventTest, InjectEvent_InjectTouch_002, TestSize.Level1) 256 { 257 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 258 char command1[] = {"uinput"}; 259 char command2[] = {"-T"}; 260 char command3[] = {"-d"}; 261 char command4[] = {"100"}; 262 char command5[] = {"200"}; 263 char *argv[] = {command1, command2, command3, command4, command5}; 264 int32_t result = inputManagerCommand->ParseCommand(5, argv); 265 EXPECT_EQ(OHOS::ERR_OK, result); 266 } 267 268 /** 269 * @tc.name:InjectEvent_InjectTouch_003 270 * @tc.desc: test inject touch up interface 271 * @tc.type: FUNC 272 * @tc.require:SR000GGQBJ 273 */ 274 HWTEST_F(InjectEventTest, InjectEvent_InjectTouch_003, TestSize.Level1) 275 { 276 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 277 char command1[] = {"uinput"}; 278 char command2[] = {"-T"}; 279 char command3[] = {"-u"}; 280 char command4[] = {"100"}; 281 char command5[] = {"200"}; 282 char *argv[] = {command1, command2, command3, command4, command5}; 283 int32_t result = inputManagerCommand->ParseCommand(5, argv); 284 EXPECT_EQ(OHOS::ERR_OK, result); 285 } 286 287 /** 288 * @tc.name:InjectEvent_InjectTouch_004 289 * @tc.desc: test inject touch click interface 290 * @tc.type: FUNC 291 * @tc.require:SR000GGQBJ 292 */ 293 HWTEST_F(InjectEventTest, InjectEvent_InjectTouch_004, TestSize.Level1) 294 { 295 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 296 char command1[] = {"uinput"}; 297 char command2[] = {"-T"}; 298 char command3[] = {"-c"}; 299 char command4[] = {"200"}; 300 char command5[] = {"1250"}; 301 char command6[] = {"200"}; 302 char *argv[] = {command1, command2, command3, command4, command5, command6}; 303 int32_t result = inputManagerCommand->ParseCommand(5, argv); 304 EXPECT_EQ(OHOS::ERR_OK, result); 305 } 306 307 /** 308 * @tc.name:InjectEvent_InjectTouch_005 309 * @tc.desc: test inject touch drag interface 310 * @tc.type: FUNC 311 * @tc.require:SR000GGQBJ 312 */ 313 HWTEST_F(InjectEventTest, InjectEvent_InjectTouch_005, TestSize.Level1) 314 { 315 std::unique_ptr<InputManagerCommand> inputManagerCommand = std::make_unique<InputManagerCommand>(); 316 char command1[] = {"uinput"}; 317 char command2[] = {"-T"}; 318 char command3[] = {"-g"}; 319 char command4[] = {"100"}; 320 char command5[] = {"200"}; 321 char command6[] = {"100"}; 322 char command7[] = {"600"}; 323 char command8[] = {"700"}; 324 char command9[] = {"3000"}; 325 char *argv[] = {command1, command2, command3, command4, command5, command6, command7, command8, command9}; 326 int32_t result = inputManagerCommand->ParseCommand(9, argv); 327 EXPECT_EQ(OHOS::ERR_OK, result); 328 } 329 } // namespace MMI 330 } // namespace OHOS