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 "get_device_object.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 class GetDeviceObjectTest : public testing::Test { 26 public: SetUpTestCase(void)27 static void SetUpTestCase(void) {} TearDownTestCase(void)28 static void TearDownTestCase(void) {} 29 }; 30 31 HWTEST_F(GetDeviceObjectTest, Test_GetDeviceObjectTest, TestSize.Level1) 32 { 33 const std::string path = "/data/json/Test_GetDeviceObjectTest.json"; 34 std::string startDeviceCmd = "mmi-virtual-device-manager start all & "; 35 std::string closeDeviceCmd = "mmi-virtual-device-manager close all"; 36 system(startDeviceCmd.c_str()); 37 std::this_thread::sleep_for(std::chrono::seconds(1)); 38 std::ifstream reader(path); 39 if (!reader.is_open()) { 40 std::this_thread::sleep_for(std::chrono::seconds(1)); 41 system(closeDeviceCmd.c_str()); 42 ASSERT_TRUE(false) << "can not open " << path; 43 } 44 Json inputEventArrays; 45 reader >> inputEventArrays; 46 reader.close(); 47 ManageInjectDevice manageInjectDevice; 48 auto ret = manageInjectDevice.TransformJsonData(inputEventArrays); 49 std::this_thread::sleep_for(std::chrono::seconds(1)); 50 system(closeDeviceCmd.c_str()); 51 EXPECT_EQ(ret, RET_OK); 52 } 53 54 HWTEST_F(GetDeviceObjectTest, Test_GetDeviceObjectTestNotFindDevice, TestSize.Level1) 55 { 56 const std::string deviceName = "temp"; 57 bool result; 58 GetDeviceObject getDeviceObject; 59 auto ret = getDeviceObject.CreateDeviceObject(deviceName); 60 if (ret == nullptr) { 61 result = true; 62 } else { 63 result = false; 64 } 65 EXPECT_EQ(result, true); 66 } 67 } // namespace