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 "processing_pen_device.h" 17 #include <gtest/gtest.h> 18 #include "manage_inject_device.h" 19 #include "msg_head.h" 20 #include "proto.h" 21 22 namespace { 23 using namespace testing::ext; 24 using namespace OHOS::MMI; 25 using namespace std; 26 class ProcessingPenDeviceTest : public testing::Test { 27 public: SetUpTestCase(void)28 static void SetUpTestCase(void) {} TearDownTestCase(void)29 static void TearDownTestCase(void) {} 30 }; 31 32 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputData, TestSize.Level1) 33 { 34 const string path = "/data/json/Test_TransformPenJsonDataToInputData.json"; 35 string startDeviceCmd = "mmi-virtual-device-manager start touchpad & "; 36 string closeDeviceCmd = "mmi-virtual-device-manager close all"; 37 system(startDeviceCmd.c_str()); 38 std::this_thread::sleep_for(std::chrono::seconds(1)); 39 std::ifstream reader(path); 40 if (!reader.is_open()) { 41 std::this_thread::sleep_for(std::chrono::seconds(1)); 42 system(closeDeviceCmd.c_str()); 43 ASSERT_TRUE(false) << "can not open " << path; 44 } 45 Json inputEventArrays; 46 reader >> inputEventArrays; 47 reader.close(); 48 ManageInjectDevice manageInjectDevice; 49 auto ret = manageInjectDevice.TransformJsonData(inputEventArrays); 50 std::this_thread::sleep_for(std::chrono::seconds(1)); 51 system(closeDeviceCmd.c_str()); 52 EXPECT_EQ(ret, RET_OK); 53 } 54 55 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataNotfindEvents, TestSize.Level1) 56 { 57 const string path = "/data/json/Test_TransformPenJsonDataToInputDataNotfindEvents.json"; 58 string startDeviceCmd = "mmi-virtual-device-manager start touchpad & "; 59 string closeDeviceCmd = "mmi-virtual-device-manager close all"; 60 system(startDeviceCmd.c_str()); 61 std::this_thread::sleep_for(std::chrono::seconds(1)); 62 std::ifstream reader(path); 63 if (!reader.is_open()) { 64 std::this_thread::sleep_for(std::chrono::seconds(1)); 65 system(closeDeviceCmd.c_str()); 66 ASSERT_TRUE(false) << "can not open " << path; 67 } 68 Json inputEventArrays; 69 reader >> inputEventArrays; 70 reader.close(); 71 ManageInjectDevice manageInjectDevice; 72 auto ret = manageInjectDevice.TransformJsonData(inputEventArrays); 73 std::this_thread::sleep_for(std::chrono::seconds(1)); 74 system(closeDeviceCmd.c_str()); 75 EXPECT_EQ(ret, RET_ERR); 76 } 77 78 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataEventsIsEmpty, TestSize.Level1) 79 { 80 const string path = "/data/json/Test_TransformPenJsonDataToInputDataEventsIsEmpty.json"; 81 string startDeviceCmd = "mmi-virtual-device-manager start touchpad & "; 82 string closeDeviceCmd = "mmi-virtual-device-manager close all"; 83 system(startDeviceCmd.c_str()); 84 std::this_thread::sleep_for(std::chrono::seconds(1)); 85 std::ifstream reader(path); 86 if (!reader.is_open()) { 87 std::this_thread::sleep_for(std::chrono::seconds(1)); 88 system(closeDeviceCmd.c_str()); 89 ASSERT_TRUE(false) << "can not open " << path; 90 } 91 Json inputEventArrays; 92 reader >> inputEventArrays; 93 reader.close(); 94 ManageInjectDevice manageInjectDevice; 95 auto ret = manageInjectDevice.TransformJsonData(inputEventArrays); 96 std::this_thread::sleep_for(std::chrono::seconds(1)); 97 system(closeDeviceCmd.c_str()); 98 EXPECT_EQ(ret, RET_ERR); 99 } 100 101 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataApprochEventError, TestSize.Level1) 102 { 103 const string path = "/data/json/Test_TransformPenJsonDataToInputDataApprochEventError.json"; 104 string startDeviceCmd = "mmi-virtual-device-manager start touchpad & "; 105 string closeDeviceCmd = "mmi-virtual-device-manager close all"; 106 system(startDeviceCmd.c_str()); 107 std::this_thread::sleep_for(std::chrono::seconds(1)); 108 std::ifstream reader(path); 109 if (!reader.is_open()) { 110 std::this_thread::sleep_for(std::chrono::seconds(1)); 111 system(closeDeviceCmd.c_str()); 112 ASSERT_TRUE(false) << "can not open " << path; 113 } 114 Json inputEventArrays; 115 reader >> inputEventArrays; 116 reader.close(); 117 ManageInjectDevice manageInjectDevice; 118 auto ret = manageInjectDevice.TransformJsonData(inputEventArrays); 119 std::this_thread::sleep_for(std::chrono::seconds(1)); 120 system(closeDeviceCmd.c_str()); 121 EXPECT_EQ(ret, RET_ERR); 122 } 123 124 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataSlideEventError, TestSize.Level1) 125 { 126 const string path = "/data/json/Test_TransformPenJsonDataToInputDataSlideEventError.json"; 127 string startDeviceCmd = "mmi-virtual-device-manager start touchpad & "; 128 string closeDeviceCmd = "mmi-virtual-device-manager close all"; 129 system(startDeviceCmd.c_str()); 130 std::this_thread::sleep_for(std::chrono::seconds(1)); 131 std::ifstream reader(path); 132 if (!reader.is_open()) { 133 std::this_thread::sleep_for(std::chrono::seconds(1)); 134 system(closeDeviceCmd.c_str()); 135 ASSERT_TRUE(false) << "can not open " << path; 136 } 137 Json inputEventArrays; 138 reader >> inputEventArrays; 139 reader.close(); 140 ManageInjectDevice manageInjectDevice; 141 auto ret = manageInjectDevice.TransformJsonData(inputEventArrays); 142 std::this_thread::sleep_for(std::chrono::seconds(1)); 143 system(closeDeviceCmd.c_str()); 144 EXPECT_EQ(ret, RET_ERR); 145 } 146 147 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataLeaveEventError, TestSize.Level1) 148 { 149 const string path = "/data/json/Test_TransformPenJsonDataToInputDataLeaveEventError.json"; 150 string startDeviceCmd = "mmi-virtual-device-manager start touchpad & "; 151 string closeDeviceCmd = "mmi-virtual-device-manager close all"; 152 system(startDeviceCmd.c_str()); 153 std::this_thread::sleep_for(std::chrono::seconds(1)); 154 std::ifstream reader(path); 155 if (!reader.is_open()) { 156 std::this_thread::sleep_for(std::chrono::seconds(1)); 157 system(closeDeviceCmd.c_str()); 158 ASSERT_TRUE(false) << "can not open " << path; 159 } 160 Json inputEventArrays; 161 reader >> inputEventArrays; 162 reader.close(); 163 ManageInjectDevice manageInjectDevice; 164 auto ret = manageInjectDevice.TransformJsonData(inputEventArrays); 165 std::this_thread::sleep_for(std::chrono::seconds(1)); 166 system(closeDeviceCmd.c_str()); 167 EXPECT_EQ(ret, RET_ERR); 168 } 169 170 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataApprochEventEventTypeError, TestSize.Level1) 171 { 172 const string path = "/data/json/Test_TransformPenJsonDataToInputDataApprochEventEventTypeError.json"; 173 string startDeviceCmd = "mmi-virtual-device-manager start touchpad & "; 174 string closeDeviceCmd = "mmi-virtual-device-manager close all"; 175 system(startDeviceCmd.c_str()); 176 std::this_thread::sleep_for(std::chrono::seconds(1)); 177 std::ifstream reader(path); 178 if (!reader.is_open()) { 179 std::this_thread::sleep_for(std::chrono::seconds(1)); 180 system(closeDeviceCmd.c_str()); 181 ASSERT_TRUE(false) << "can not open " << path; 182 } 183 Json inputEventArrays; 184 reader >> inputEventArrays; 185 reader.close(); 186 ManageInjectDevice manageInjectDevice; 187 auto ret = manageInjectDevice.TransformJsonData(inputEventArrays); 188 std::this_thread::sleep_for(std::chrono::seconds(1)); 189 system(closeDeviceCmd.c_str()); 190 EXPECT_EQ(ret, RET_ERR); 191 } 192 193 HWTEST_F(ProcessingPenDeviceTest, Test_TransformPenJsonDataToInputDataLeaveEventEventTypeError, TestSize.Level1) 194 { 195 const string path = "/data/json/Test_TransformPenJsonDataToInputDataLeaveEventEventTypeError.json"; 196 string startDeviceCmd = "mmi-virtual-device-manager start touchpad & "; 197 string closeDeviceCmd = "mmi-virtual-device-manager close all"; 198 system(startDeviceCmd.c_str()); 199 std::this_thread::sleep_for(std::chrono::seconds(1)); 200 std::ifstream reader(path); 201 if (!reader.is_open()) { 202 std::this_thread::sleep_for(std::chrono::seconds(1)); 203 system(closeDeviceCmd.c_str()); 204 ASSERT_TRUE(false) << "can not open " << path; 205 } 206 Json inputEventArrays; 207 reader >> inputEventArrays; 208 reader.close(); 209 ManageInjectDevice manageInjectDevice; 210 auto ret = manageInjectDevice.TransformJsonData(inputEventArrays); 211 std::this_thread::sleep_for(std::chrono::seconds(1)); 212 system(closeDeviceCmd.c_str()); 213 EXPECT_EQ(ret, RET_ERR); 214 } 215 } // namespace