• 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 "processing_keyboard_device.h"
17 #include <gtest/gtest.h>
18 #include "proto.h"
19 #include "manage_inject_device.h"
20 #include "msg_head.h"
21 
22 namespace {
23 using namespace testing::ext;
24 using namespace OHOS::MMI;
25 using namespace std;
26 class ProcessingKeyboardDeviceTest : public testing::Test {
27 public:
SetUpTestCase(void)28     static void SetUpTestCase(void) {}
TearDownTestCase(void)29     static void TearDownTestCase(void) {}
30 };
31 
32 HWTEST_F(ProcessingKeyboardDeviceTest, Test_TransformKeyBoardJsonDataToInputData, TestSize.Level1)
33 {
34     const string path = "/data/json/Test_TransformKeyBoardJsonDataToInputData.json";
35     string startDeviceCmd = "mmi-virtual-device-manager start keyboard & ";
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(ProcessingKeyboardDeviceTest, Test_TransformKeyBoardJsonDataToInputDataEventsIsEmpty, TestSize.Level1)
56 {
57     const string path = "/data/json/Test_TransformKeyBoardJsonDataToInputDataEventsIsEmpty.json";
58     string startDeviceCmd = "mmi-virtual-device-manager start keyboard & ";
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     system(startDeviceCmd.c_str());
74     std::this_thread::sleep_for(std::chrono::seconds(1));
75     EXPECT_EQ(ret, RET_ERR);
76 }
77 } // namespace
78