• 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 
18 #include "manage_inject_device.h"
19 #include "msg_head.h"
20 #include "processing_keyboard_device.h"
21 #include "proto.h"
22 
23 namespace OHOS {
24 namespace MMI {
25 namespace {
26 using namespace testing::ext;
27 } // namespace
28 
29 class ProcessingMouseDeviceTest : public testing::Test {
30 public:
SetUpTestCase(void)31     static void SetUpTestCase(void) {}
TearDownTestCase(void)32     static void TearDownTestCase(void) {}
33 };
34 
35 /**
36  * @tc.name:Test_TransformJsonDataToInputData
37  * @tc.desc:Verify ManageInjectDevice function TransformJsonData
38  * @tc.type: FUNC
39  * @tc.require:
40  */
41 HWTEST_F(ProcessingMouseDeviceTest, Test_TransformJsonDataToInputData, TestSize.Level1)
42 {
43     const std::string path = "/data/json/Test_TransformMouseJsonDataToInputData.json";
44     std::string startDeviceCmd = "vuinput start mouse & ";
45     std::string closeDeviceCmd = "vuinput close all";
46     FILE* startDevice = popen(startDeviceCmd.c_str(), "rw");
47     if (!startDevice) {
48         ASSERT_TRUE(false) << "Start device failed";
49     }
50     pclose(startDevice);
51     std::this_thread::sleep_for(std::chrono::seconds(1));
52     std::string jsonBuf = ReadJsonFile(path);
53     if (jsonBuf.empty()) {
54         ASSERT_TRUE(false) << "Read file failed" << path;
55     }
56     ManageInjectDevice manageInjectDevice;
57     auto ret = manageInjectDevice.TransformJsonData(DataInit(jsonBuf, false));
58     FILE* closeDevice = popen(closeDeviceCmd.c_str(), "rw");
59     if (!closeDevice) {
60         ASSERT_TRUE(false) << "Close device failed";
61     }
62     pclose(closeDevice);
63     std::this_thread::sleep_for(std::chrono::seconds(1));
64     EXPECT_EQ(ret, RET_OK);
65 }
66 } // namespace MMI
67 } // namespace OHOS