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 18 #include "manage_inject_device.h" 19 #include "msg_head.h" 20 #include "processing_pen_device.h" 21 #include "proto.h" 22 23 namespace OHOS { 24 namespace MMI { 25 namespace { 26 using namespace testing::ext; 27 using namespace OHOS::MMI; 28 } // namespace 29 30 class ProcessingPenDeviceTest : public testing::Test { 31 public: SetUpTestCase(void)32 static void SetUpTestCase(void) {} TearDownTestCase(void)33 static void TearDownTestCase(void) {} 34 }; 35 36 /** 37 * @tc.name:Test_TransformPenJsonDataToInputData 38 * @tc.desc:Verify ManageInjectDevice function TransformJsonData 39 * @tc.type: FUNC 40 * @tc.require: 41 */ 42 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputData, TestSize.Level1) 43 { 44 const std::string path = "/data/json/Test_TransformPenJsonDataToInputData.json"; 45 std::string startDeviceCmd = "vuinput start touchpad & "; 46 std::string closeDeviceCmd = "vuinput close all"; 47 FILE* startDevice = popen(startDeviceCmd.c_str(), "rw"); 48 if (!startDevice) { 49 ASSERT_TRUE(false) << "Start device failed"; 50 } 51 pclose(startDevice); 52 std::this_thread::sleep_for(std::chrono::seconds(1)); 53 std::string jsonBuf = ReadJsonFile(path); 54 if (jsonBuf.empty()) { 55 ASSERT_TRUE(false) << "Read file failed" << path; 56 } 57 ManageInjectDevice manageInjectDevice; 58 auto ret = manageInjectDevice.TransformJsonData(DataInit(jsonBuf, false)); 59 FILE* closeDevice = popen(closeDeviceCmd.c_str(), "rw"); 60 if (!closeDevice) { 61 ASSERT_TRUE(false) << "Close device failed"; 62 } 63 pclose(closeDevice); 64 std::this_thread::sleep_for(std::chrono::seconds(1)); 65 EXPECT_EQ(ret, RET_OK); 66 } 67 68 /** 69 * @tc.name:Test_TransformPenJsonDataToInputDataNotfindEvents 70 * @tc.desc:Verify ManageInjectDevice function TransformJsonData 71 * @tc.type: FUNC 72 * @tc.require: 73 */ 74 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataNotfindEvents, TestSize.Level1) 75 { 76 const std::string path = "/data/json/Test_TransformPenJsonDataToInputDataNotfindEvents.json"; 77 std::string startDeviceCmd = "vuinput start touchpad & "; 78 std::string closeDeviceCmd = "vuinput close all"; 79 FILE* startDevice = popen(startDeviceCmd.c_str(), "rw"); 80 if (!startDevice) { 81 ASSERT_TRUE(false) << "Start device failed"; 82 } 83 pclose(startDevice); 84 std::string jsonBuf = ReadJsonFile(path); 85 if (jsonBuf.empty()) { 86 ASSERT_TRUE(false) << "Read file failed" << path; 87 } 88 ManageInjectDevice manageInjectDevice; 89 auto ret = manageInjectDevice.TransformJsonData(DataInit(jsonBuf, false)); 90 FILE* closeDevice = popen(closeDeviceCmd.c_str(), "rw"); 91 if (!closeDevice) { 92 ASSERT_TRUE(false) << "Close device failed"; 93 } 94 pclose(closeDevice); 95 std::this_thread::sleep_for(std::chrono::seconds(1)); 96 EXPECT_EQ(ret, RET_ERR); 97 } 98 99 /** 100 * @tc.name:Test_TransformPenJsonDataToInputDataEventsIsEmpty 101 * @tc.desc:Verify ManageInjectDevice function TransformJsonData 102 * @tc.type: FUNC 103 * @tc.require: 104 */ 105 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataEventsIsEmpty, TestSize.Level1) 106 { 107 const std::string path = "/data/json/Test_TransformPenJsonDataToInputDataEventsIsEmpty.json"; 108 std::string startDeviceCmd = "vuinput start touchpad & "; 109 std::string closeDeviceCmd = "vuinput close all"; 110 FILE* startDevice = popen(startDeviceCmd.c_str(), "rw"); 111 if (!startDevice) { 112 ASSERT_TRUE(false) << "Start device failed"; 113 } 114 pclose(startDevice); 115 std::string jsonBuf = ReadJsonFile(path); 116 if (jsonBuf.empty()) { 117 ASSERT_TRUE(false) << "Read file failed" << path; 118 } 119 ManageInjectDevice manageInjectDevice; 120 auto ret = manageInjectDevice.TransformJsonData(DataInit(jsonBuf, false)); 121 FILE* closeDevice = popen(closeDeviceCmd.c_str(), "rw"); 122 if (!closeDevice) { 123 ASSERT_TRUE(false) << "Close device failed"; 124 } 125 pclose(closeDevice); 126 std::this_thread::sleep_for(std::chrono::seconds(1)); 127 EXPECT_EQ(ret, RET_ERR); 128 } 129 130 /** 131 * @tc.name:Test_TransformPenJsonDataToInputDataApproachEventError 132 * @tc.desc:Verify ManageInjectDevice function TransformJsonData 133 * @tc.type: FUNC 134 * @tc.require: 135 */ 136 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataApproachEventError, TestSize.Level1) 137 { 138 const std::string path = "/data/json/Test_TransformPenJsonDataToInputDataApprochEventError.json"; 139 std::string startDeviceCmd = "vuinput start touchpad & "; 140 std::string closeDeviceCmd = "vuinput close all"; 141 FILE* startDevice = popen(startDeviceCmd.c_str(), "rw"); 142 if (!startDevice) { 143 ASSERT_TRUE(false) << "Start device failed"; 144 } 145 pclose(startDevice); 146 std::string jsonBuf = ReadJsonFile(path); 147 if (jsonBuf.empty()) { 148 ASSERT_TRUE(false) << "Read file failed" << path; 149 } 150 ManageInjectDevice manageInjectDevice; 151 auto ret = manageInjectDevice.TransformJsonData(DataInit(jsonBuf, false)); 152 FILE* closeDevice = popen(closeDeviceCmd.c_str(), "rw"); 153 if (!closeDevice) { 154 ASSERT_TRUE(false) << "Close device failed"; 155 } 156 pclose(closeDevice); 157 std::this_thread::sleep_for(std::chrono::seconds(1)); 158 EXPECT_EQ(ret, RET_ERR); 159 } 160 161 /** 162 * @tc.name:Test_TransformPenJsonDataToInputDataSlideEventError 163 * @tc.desc:Verify ManageInjectDevice function TransformJsonData 164 * @tc.type: FUNC 165 * @tc.require: 166 */ 167 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataSlideEventError, TestSize.Level1) 168 { 169 const std::string path = "/data/json/Test_TransformPenJsonDataToInputDataSlideEventError.json"; 170 std::string startDeviceCmd = "vuinput start touchpad & "; 171 std::string closeDeviceCmd = "vuinput close all"; 172 FILE* startDevice = popen(startDeviceCmd.c_str(), "rw"); 173 if (!startDevice) { 174 ASSERT_TRUE(false) << "Start device failed"; 175 } 176 pclose(startDevice); 177 std::string jsonBuf = ReadJsonFile(path); 178 if (jsonBuf.empty()) { 179 ASSERT_TRUE(false) << "Read file failed" << path; 180 } 181 ManageInjectDevice manageInjectDevice; 182 auto ret = manageInjectDevice.TransformJsonData(DataInit(jsonBuf, false)); 183 FILE* closeDevice = popen(closeDeviceCmd.c_str(), "rw"); 184 if (!closeDevice) { 185 ASSERT_TRUE(false) << "Close device failed"; 186 } 187 pclose(closeDevice); 188 std::this_thread::sleep_for(std::chrono::seconds(1)); 189 EXPECT_EQ(ret, RET_ERR); 190 } 191 192 /** 193 * @tc.name:Test_TransformPenJsonDataToInputDataLeaveEventError 194 * @tc.desc:Verify ManageInjectDevice function TransformJsonData 195 * @tc.type: FUNC 196 * @tc.require: 197 */ 198 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataLeaveEventError, TestSize.Level1) 199 { 200 const std::string path = "/data/json/Test_TransformPenJsonDataToInputDataLeaveEventError.json"; 201 std::string startDeviceCmd = "vuinput start touchpad & "; 202 std::string closeDeviceCmd = "vuinput close all"; 203 FILE* startDevice = popen(startDeviceCmd.c_str(), "rw"); 204 if (!startDevice) { 205 ASSERT_TRUE(false) << "Start device failed"; 206 } 207 pclose(startDevice); 208 std::string jsonBuf = ReadJsonFile(path); 209 if (jsonBuf.empty()) { 210 ASSERT_TRUE(false) << "Read file failed" << path; 211 } 212 ManageInjectDevice manageInjectDevice; 213 auto ret = manageInjectDevice.TransformJsonData(DataInit(jsonBuf, false)); 214 FILE* closeDevice = popen(closeDeviceCmd.c_str(), "rw"); 215 if (!closeDevice) { 216 ASSERT_TRUE(false) << "Close device failed"; 217 } 218 pclose(closeDevice); 219 std::this_thread::sleep_for(std::chrono::seconds(1)); 220 EXPECT_EQ(ret, RET_ERR); 221 } 222 223 /** 224 * @tc.name:Test_TransformPenJsonDataToInputDataApproachEventEventTypeError 225 * @tc.desc:Verify ManageInjectDevice function TransformJsonData 226 * @tc.type: FUNC 227 * @tc.require: 228 */ 229 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataApproachEventEventTypeError, TestSize.Level1) 230 { 231 const std::string path = "/data/json/Test_TransformPenJsonDataToInputDataApprochEventEventTypeError.json"; 232 std::string startDeviceCmd = "vuinput start touchpad & "; 233 std::string closeDeviceCmd = "vuinput close all"; 234 FILE* startDevice = popen(startDeviceCmd.c_str(), "rw"); 235 if (!startDevice) { 236 ASSERT_TRUE(false) << "Start device failed"; 237 } 238 pclose(startDevice); 239 std::string jsonBuf = ReadJsonFile(path); 240 if (jsonBuf.empty()) { 241 ASSERT_TRUE(false) << "Read file failed" << path; 242 } 243 ManageInjectDevice manageInjectDevice; 244 auto ret = manageInjectDevice.TransformJsonData(DataInit(jsonBuf, false)); 245 FILE* closeDevice = popen(closeDeviceCmd.c_str(), "rw"); 246 if (!closeDevice) { 247 ASSERT_TRUE(false) << "Close device failed"; 248 } 249 pclose(closeDevice); 250 std::this_thread::sleep_for(std::chrono::seconds(1)); 251 EXPECT_EQ(ret, RET_ERR); 252 } 253 254 /** 255 * @tc.name:Test_TransformPenJsonDataToInputDataLeaveEventEventTypeError 256 * @tc.desc:Verify ManageInjectDevice function TransformJsonData 257 * @tc.type: FUNC 258 * @tc.require: 259 */ 260 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataLeaveEventEventTypeError, TestSize.Level1) 261 { 262 const std::string path = "/data/json/Test_TransformPenJsonDataToInputDataLeaveEventEventTypeError.json"; 263 std::string startDeviceCmd = "vuinput start touchpad & "; 264 std::string closeDeviceCmd = "vuinput close all"; 265 FILE* startDevice = popen(startDeviceCmd.c_str(), "rw"); 266 if (!startDevice) { 267 ASSERT_TRUE(false) << "Start device failed"; 268 } 269 pclose(startDevice); 270 std::string jsonBuf = ReadJsonFile(path); 271 if (jsonBuf.empty()) { 272 ASSERT_TRUE(false) << "Read file failed" << path; 273 } 274 ManageInjectDevice manageInjectDevice; 275 auto ret = manageInjectDevice.TransformJsonData(DataInit(jsonBuf, false)); 276 FILE* closeDevice = popen(closeDeviceCmd.c_str(), "rw"); 277 if (!closeDevice) { 278 ASSERT_TRUE(false) << "Close device failed"; 279 } 280 pclose(closeDevice); 281 std::this_thread::sleep_for(std::chrono::seconds(1)); 282 EXPECT_EQ(ret, RET_ERR); 283 } 284 } // namespace MMI 285 } // namespace OHOS