• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "msg_head.h"
18 #include "proto.h"
19 #define private public
20 #include "manage_inject_device.h"
21 #undef private
22 
23 namespace {
24 using namespace testing::ext;
25 using namespace OHOS::MMI;
26 using namespace std;
27 class ManageInjectDeviceTest : public testing::Test {
28 public:
SetUpTestCase(void)29     static void SetUpTestCase(void) {}
TearDownTestCase(void)30     static void TearDownTestCase(void) {}
31 };
32 
33 HWTEST_F(ManageInjectDeviceTest, Test_TransformJsonDataCheckFileIsEmpty, TestSize.Level1)
34 {
35     Json inputEventArrays;
36     inputEventArrays.clear();
37     ManageInjectDevice manageInjectDevice;
38     auto ret = manageInjectDevice.TransformJsonData(inputEventArrays);
39     EXPECT_EQ(ret, RET_ERR);
40 }
41 
42 HWTEST_F(ManageInjectDeviceTest, Test_TransformJsonDataCheckFileNotEmpty, TestSize.Level1)
43 {
44     const string path = "/data/json/Test_TransformJsonDataCheckFileNotEmpty.json";
45     string startDeviceCmd = "mmi-virtual-device-manager start all & ";
46     string closeDeviceCmd = "mmi-virtual-device-manager close all";
47     system(startDeviceCmd.c_str());
48     std::this_thread::sleep_for(std::chrono::seconds(1));
49     std::ifstream reader(path);
50     if (!reader.is_open()) {
51         std::this_thread::sleep_for(std::chrono::seconds(1));
52         system(closeDeviceCmd.c_str());
53         ASSERT_TRUE(false) << "can not open " << path;
54     }
55     Json inputEventArrays;
56     reader >> inputEventArrays;
57     reader.close();
58     ManageInjectDevice manageInjectDevice;
59     auto ret = manageInjectDevice.TransformJsonData(inputEventArrays);
60     std::this_thread::sleep_for(std::chrono::seconds(1));
61     system(closeDeviceCmd.c_str());
62     EXPECT_EQ(ret, RET_OK);
63 }
64 
65 HWTEST_F(ManageInjectDeviceTest, Test_TransformJsonDataGetDeviceNodeError, TestSize.Level1)
66 {
67     const string path = "/data/json/Test_TransformJsonDataGetDeviceNodeError.json";
68     string startDeviceCmd = "mmi-virtual-device-manager start all & ";
69     string closeDeviceCmd = "mmi-virtual-device-manager close all";
70     system(startDeviceCmd.c_str());
71     std::this_thread::sleep_for(std::chrono::seconds(1));
72     std::ifstream reader(path);
73     if (!reader.is_open()) {
74         std::this_thread::sleep_for(std::chrono::seconds(1));
75         system(closeDeviceCmd.c_str());
76         ASSERT_TRUE(false) << "can not open " << path;
77     }
78     Json inputEventArrays;
79     reader >> inputEventArrays;
80     reader.close();
81     ManageInjectDevice manageInjectDevice;
82     auto ret = manageInjectDevice.TransformJsonData(inputEventArrays);
83     std::this_thread::sleep_for(std::chrono::seconds(1));
84     system(closeDeviceCmd.c_str());
85     EXPECT_EQ(ret, RET_ERR);
86 }
87 
88 HWTEST_F(ManageInjectDeviceTest, Test_SendEventToDeviveNodeError, TestSize.Level1)
89 {
90     ManageInjectDevice manageInjectDevice;
91     InputEventArray inputEventArray = {};
92     inputEventArray.target = "";
93     auto ret = manageInjectDevice.SendEventToDeviveNode(inputEventArray);
94     EXPECT_EQ(ret, RET_ERR);
95 }
96 } // namespace