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 #include <gtest/gtest.h> 16 #include "virtual_device.h" 17 18 namespace OHOS { 19 namespace MMI { 20 namespace { 21 using namespace testing::ext; 22 using namespace OHOS::MMI; 23 } // namespace 24 25 class VirtualDeviceTest : public testing::Test { 26 public: SetUpTestCase(void)27 static void SetUpTestCase(void) {} TearDownTestCase(void)28 static void TearDownTestCase(void) {} 29 30 const std::string DEVICE = "Virtual Mouse"; 31 const uint16_t BUS_TYPE = BUS_USB; 32 const uint16_t VENDOR_ID = 0x93a; 33 const uint16_t PRODUCT_ID = 0x2510; 34 }; 35 36 /** 37 * @tc.name:Test_CreateHandle_mouse 38 * @tc.desc:Verify VirtualDevice function CreateHandle 39 * @tc.type: FUNC 40 * @tc.require: 41 */ 42 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_mouse, TestSize.Level1) 43 { 44 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 45 std::string deviceType = "mouse"; 46 auto ret = device.CreateHandle(deviceType); 47 EXPECT_TRUE(ret); 48 } 49 50 /** 51 * @tc.name:Test_CreateHandle_keyboard 52 * @tc.desc:Verify VirtualDevice function CreateHandle 53 * @tc.type: FUNC 54 * @tc.require: 55 */ 56 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_keyboard, TestSize.Level1) 57 { 58 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 59 std::string deviceType = "keyboard"; 60 auto ret = device.CreateHandle(deviceType); 61 EXPECT_TRUE(ret); 62 } 63 64 /** 65 * @tc.name:Test_CreateHandle_knob 66 * @tc.desc:Verify VirtualDevice function CreateHandle 67 * @tc.type: FUNC 68 * @tc.require: 69 */ 70 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_knob, TestSize.Level1) 71 { 72 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 73 std::string deviceType = "knob"; 74 auto ret = device.CreateHandle(deviceType); 75 EXPECT_TRUE(ret); 76 } 77 78 /** 79 * @tc.name:Test_CreateHandle_joystick 80 * @tc.desc:Verify VirtualDevice function CreateHandle 81 * @tc.type: FUNC 82 * @tc.require: 83 */ 84 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_joystick, TestSize.Level1) 85 { 86 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 87 std::string deviceType = "joystick"; 88 auto ret = device.CreateHandle(deviceType); 89 EXPECT_TRUE(ret); 90 } 91 92 /** 93 * @tc.name:Test_CreateHandle_trackball 94 * @tc.desc:Verify VirtualDevice function CreateHandle 95 * @tc.type: FUNC 96 * @tc.require: 97 */ 98 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_trackball, TestSize.Level1) 99 { 100 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 101 std::string deviceType = "trackball"; 102 auto ret = device.CreateHandle(deviceType); 103 EXPECT_TRUE(ret); 104 } 105 106 /** 107 * @tc.name:Test_CreateHandle_remotecontrol 108 * @tc.desc:Verify VirtualDevice function CreateHandle 109 * @tc.type: FUNC 110 * @tc.require: 111 */ 112 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_remotecontrol, TestSize.Level1) 113 { 114 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 115 std::string deviceType = "remotecontrol"; 116 auto ret = device.CreateHandle(deviceType); 117 EXPECT_TRUE(ret); 118 } 119 120 /** 121 * @tc.name:Test_CreateHandle_trackpad 122 * @tc.desc:Verify VirtualDevice function CreateHandle 123 * @tc.type: FUNC 124 * @tc.require: 125 */ 126 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_trackpad, TestSize.Level1) 127 { 128 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 129 std::string deviceType = "trackpad"; 130 auto ret = device.CreateHandle(deviceType); 131 EXPECT_TRUE(ret); 132 } 133 134 /** 135 * @tc.name:Test_CreateHandle_gamepad 136 * @tc.desc:Verify VirtualDevice function CreateHandle 137 * @tc.type: FUNC 138 * @tc.require: 139 */ 140 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_gamepad, TestSize.Level1) 141 { 142 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 143 std::string deviceType = "gamepad"; 144 auto ret = device.CreateHandle(deviceType); 145 EXPECT_TRUE(ret); 146 } 147 148 /** 149 * @tc.name:Test_CreateHandle_touchpad 150 * @tc.desc:Verify VirtualDevice function CreateHandle 151 * @tc.type: FUNC 152 * @tc.require: 153 */ 154 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_touchpad, TestSize.Level1) 155 { 156 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 157 std::string deviceType = "touchpad"; 158 auto ret = device.CreateHandle(deviceType); 159 EXPECT_TRUE(ret); 160 } 161 162 /** 163 * @tc.name:Test_CreateHandle_touchscreen 164 * @tc.desc:Verify VirtualDevice function CreateHandle 165 * @tc.type: FUNC 166 * @tc.require: 167 */ 168 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_touchscreen, TestSize.Level1) 169 { 170 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 171 std::string deviceType = "touchscreen"; 172 auto ret = device.CreateHandle(deviceType); 173 EXPECT_TRUE(ret); 174 } 175 176 /** 177 * @tc.name:Test_CreateHandle_phone 178 * @tc.desc:Verify VirtualDevice function CreateHandle 179 * @tc.type: FUNC 180 * @tc.require: 181 */ 182 HWTEST_F(VirtualDeviceTest, Test_CreateHandle_phone, TestSize.Level1) 183 { 184 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 185 std::string deviceType = "phone"; 186 auto ret = device.CreateHandle(deviceType); 187 EXPECT_FALSE(ret); 188 } 189 190 /** 191 * @tc.name:Test_AddDevice_false01 192 * @tc.desc:Verify VirtualDevice function AddDevice 193 * @tc.type: FUNC 194 * @tc.require: 195 */ 196 HWTEST_F(VirtualDeviceTest, Test_AddDevice_false01, TestSize.Level1) 197 { 198 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 199 std::string deviceName = ""; 200 auto ret = device.AddDevice(deviceName); 201 EXPECT_FALSE(ret); 202 } 203 204 /** 205 * @tc.name:Test_AddDevice_true 206 * @tc.desc:Verify VirtualDevice function AddDevice 207 * @tc.type: FUNC 208 * @tc.require: 209 */ 210 HWTEST_F(VirtualDeviceTest, Test_AddDevice_true, TestSize.Level1) 211 { 212 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 213 std::string deviceName = "mouse"; 214 auto ret = device.AddDevice(deviceName); 215 EXPECT_TRUE(ret); 216 } 217 218 /** 219 * @tc.name:Test_AddDevice_false02 220 * @tc.desc:Verify VirtualDevice function AddDevice 221 * @tc.type: FUNC 222 * @tc.require: 223 */ 224 HWTEST_F(VirtualDeviceTest, Test_AddDevice_false02, TestSize.Level1) 225 { 226 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 227 std::string deviceName = "falseName"; 228 auto ret = device.AddDevice(deviceName); 229 EXPECT_FALSE(ret); 230 } 231 232 /** 233 * @tc.name:Test_CloseDevice_flase02 234 * @tc.desc:Verify VirtualDevice function CloseDevice 235 * @tc.type: FUNC 236 * @tc.require: 237 */ 238 HWTEST_F(VirtualDeviceTest, Test_CloseDevice_flase02, TestSize.Level1) 239 { 240 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 241 std::vector<std::string> fileList; 242 std::string fileName = "falseArgv"; 243 fileList.push_back("close "); 244 fileList.push_back("falseArgv "); 245 auto ret = device.CloseDevice(fileName, fileList); 246 EXPECT_FALSE(ret); 247 } 248 249 /** 250 * @tc.name:Test_FindDevice_listfalse01 251 * @tc.desc:Verify VirtualDevice function CommandBranch 252 * @tc.type: FUNC 253 * @tc.require: 254 */ 255 HWTEST_F(VirtualDeviceTest, Test_FindDevice_listfalse01, TestSize.Level1) 256 { 257 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 258 std::vector<std::string> argvList; 259 argvList.push_back("binName "); 260 argvList.push_back("list"); 261 auto ret = device.CommandBranch(argvList); 262 EXPECT_FALSE(ret); 263 } 264 265 /** 266 * @tc.name:Test_FindDevice_listfalse02 267 * @tc.desc:Verify VirtualDevice function CommandBranch 268 * @tc.type: FUNC 269 * @tc.require: 270 */ 271 HWTEST_F(VirtualDeviceTest, Test_FindDevice_listfalse02, TestSize.Level1) 272 { 273 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 274 std::vector<std::string> argvList; 275 argvList.push_back("binName "); 276 argvList.push_back("list "); 277 argvList.push_back("falseArgv"); 278 auto ret = device.CommandBranch(argvList); 279 EXPECT_FALSE(ret); 280 } 281 282 /** 283 * @tc.name:Test_FindDevice_addFalse 284 * @tc.desc:Verify VirtualDevice function CommandBranch 285 * @tc.type: FUNC 286 * @tc.require: 287 */ 288 HWTEST_F(VirtualDeviceTest, Test_FindDevice_addFalse, TestSize.Level1) 289 { 290 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 291 std::vector<std::string> argvList; 292 argvList.push_back("binName "); 293 argvList.push_back("start "); 294 argvList.push_back("falseArgv"); 295 auto ret = device.CommandBranch(argvList); 296 EXPECT_FALSE(ret); 297 } 298 299 /** 300 * @tc.name:Test_FindDevice_addTrue 301 * @tc.desc:Verify VirtualDevice function CommandBranch 302 * @tc.type: FUNC 303 * @tc.require: 304 */ 305 HWTEST_F(VirtualDeviceTest, Test_FindDevice_addTrue, TestSize.Level1) 306 { 307 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 308 std::vector<std::string> argvList; 309 argvList.push_back("binName "); 310 argvList.push_back("start"); 311 argvList.push_back("mouse"); 312 auto ret = device.CommandBranch(argvList); 313 EXPECT_TRUE(ret); 314 } 315 316 /** 317 * @tc.name:Test_FindDevice_closeFalse01 318 * @tc.desc:Verify VirtualDevice function CommandBranch 319 * @tc.type: FUNC 320 * @tc.require: 321 */ 322 HWTEST_F(VirtualDeviceTest, Test_FindDevice_closeFalse01, TestSize.Level1) 323 { 324 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 325 std::vector<std::string> argvList; 326 argvList.push_back("binName "); 327 argvList.push_back("close "); 328 argvList.push_back("falsePid"); 329 auto ret = device.CommandBranch(argvList); 330 EXPECT_FALSE(ret); 331 } 332 333 /** 334 * @tc.name:Test_FindDevice_closeTrue01 335 * @tc.desc:Verify VirtualDevice function CommandBranch 336 * @tc.type: FUNC 337 * @tc.require: 338 */ 339 HWTEST_F(VirtualDeviceTest, Test_FindDevice_closeTrue01, TestSize.Level1) 340 { 341 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 342 std::string symbolFileTest; 343 symbolFileTest.append(g_folderPath).append("1111111").append("_").append("testDevice"); 344 std::ofstream flagFile; 345 flagFile.open(symbolFileTest.c_str()); 346 std::vector<std::string> argvList; 347 argvList.push_back("binName "); 348 argvList.push_back("close "); 349 argvList.push_back("1111111"); 350 auto ret = device.CommandBranch(argvList); 351 EXPECT_FALSE(ret); 352 } 353 354 /** 355 * @tc.name:Test_FindDevice_mkdirFalse01 356 * @tc.desc:Verify VirtualDevice function CommandBranch 357 * @tc.type: FUNC 358 * @tc.require: 359 */ 360 HWTEST_F(VirtualDeviceTest, Test_FindDevice_mkdirFalse01, TestSize.Level1) 361 { 362 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 363 std::vector<std::string> argvList; 364 argvList.push_back("binName "); 365 argvList.push_back("close "); 366 argvList.push_back("falsePid"); 367 auto ret = device.CommandBranch(argvList); 368 EXPECT_FALSE(ret); 369 } 370 371 /** 372 * @tc.name:Test_FindDevice_False01 373 * @tc.desc:Verify VirtualDevice function CommandBranch 374 * @tc.type: FUNC 375 * @tc.require: 376 */ 377 HWTEST_F(VirtualDeviceTest, Test_FindDevice_False01, TestSize.Level1) 378 { 379 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 380 std::vector<std::string> argvList; 381 argvList.push_back("binName "); 382 argvList.push_back("falseArgv "); 383 auto ret = device.CommandBranch(argvList); 384 EXPECT_FALSE(ret); 385 } 386 387 /** 388 * @tc.name:Test_DoIoctl_false 389 * @tc.desc:Verify VirtualDevice function DoIoctl 390 * @tc.type: FUNC 391 * @tc.require: 392 */ 393 HWTEST_F(VirtualDeviceTest, Test_DoIoctl_false, TestSize.Level1) 394 { 395 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 396 auto ret = device.DoIoctl(-1, UI_SET_KEYBIT, KEY_POWER); 397 EXPECT_FALSE(ret); 398 } 399 400 /** 401 * @tc.name:Test_SetUp_01 402 * @tc.desc:Verify VirtualDevice function SetUp 403 * @tc.type: FUNC 404 * @tc.require: 405 */ 406 HWTEST_F(VirtualDeviceTest, Test_SetUp_01, TestSize.Level1) 407 { 408 VirtualDevice device(DEVICE, BUS_TYPE, VENDOR_ID, PRODUCT_ID); 409 auto ret = device.SetUp(); 410 EXPECT_TRUE(ret); 411 } 412 } // namespace MMI 413 } // namespace OHOS