1 /*
2 * Copyright (c) 2022-2023 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 <sys/time.h>
18
19 #include <cstdint>
20 #include <functional>
21 #include <string>
22 #include <thread>
23 #include <vector>
24
25 #include "global.h"
26 #include "im_common_event_manager.h"
27 #include "input_manager.h"
28 #include "input_method_controller.h"
29 #include "key_event.h"
30 #include "key_event_util.h"
31 #include "pointer_event.h"
32
33 namespace OHOS {
34 namespace MiscServices {
35 using namespace testing::ext;
36 using namespace MMI;
37 namespace {
38 constexpr int32_t TIME_WAIT_FOR_HANDLE_KEY_EVENT = 10000;
39 } // namespace
40
41 class InputMethodServiceTest : public testing::Test {
42 public:
43 static void SetUpTestCase(void);
44 static void TearDownTestCase(void);
45 void SetUp();
46 void TearDown();
47 };
48
SetUpTestCase(void)49 void InputMethodServiceTest::SetUpTestCase(void)
50 {
51 IMSA_HILOGI("InputMethodServiceTest::SetUpTestCase");
52 }
53
TearDownTestCase(void)54 void InputMethodServiceTest::TearDownTestCase(void)
55 {
56 IMSA_HILOGI("InputMethodServiceTest::TearDownTestCase");
57 }
58
SetUp(void)59 void InputMethodServiceTest::SetUp(void)
60 {
61 IMSA_HILOGI("InputMethodServiceTest::SetUp");
62 }
63
TearDown(void)64 void InputMethodServiceTest::TearDown(void)
65 {
66 IMSA_HILOGI("InputMethodServiceTest::TearDown");
67 }
68
69 /**
70 * @tc.name: test_KeyEvent_UNKNOWN_001
71 * @tc.desc: test KeyEvent Callback.
72 * @tc.type: FUNC
73 */
74 HWTEST_F(InputMethodServiceTest, test_KeyEvent_UNKNOWN_001, TestSize.Level0)
75 {
76 IMSA_HILOGI("test_KeyEvent_UNKNOWN_001 TEST START");
77 bool result = KeyEventUtil::SimulateKeyEvent(MMI::KeyEvent::KEYCODE_0);
78 EXPECT_TRUE(result);
79 usleep(TIME_WAIT_FOR_HANDLE_KEY_EVENT);
80 }
81
82 /**
83 * @tc.name: test_KeyEvent_UNKNOWN_002
84 * @tc.desc: test KeyEvent Callback.
85 * @tc.type: FUNC
86 */
87 HWTEST_F(InputMethodServiceTest, test_KeyEvent_UNKNOWN_002, TestSize.Level0)
88 {
89 IMSA_HILOGI("test_KeyEvent_UNKNOWN_002 TEST START");
90 bool result = KeyEventUtil::SimulateKeyEvents({ MMI::KeyEvent::KEYCODE_0, MMI::KeyEvent::KEYCODE_1 });
91 EXPECT_TRUE(result);
92 usleep(TIME_WAIT_FOR_HANDLE_KEY_EVENT);
93 }
94
95 /**
96 * @tc.name: test_KeyEvent_CAPS_001
97 * @tc.desc: test KeyEvent Callback.
98 * @tc.type: FUNC
99 */
100 HWTEST_F(InputMethodServiceTest, test_KeyEvent_CAPS_001, TestSize.Level0)
101 {
102 IMSA_HILOGI("test_KeyEvent_CAPS_001 TEST START");
103 bool result = KeyEventUtil::SimulateKeyEvent(MMI::KeyEvent::KEYCODE_CAPS_LOCK);
104 EXPECT_TRUE(result);
105 usleep(TIME_WAIT_FOR_HANDLE_KEY_EVENT);
106 }
107
108 /**
109 * @tc.name: test_KeyEvent_CTRL_001
110 * @tc.desc: test KeyEvent Callback.
111 * @tc.type: FUNC
112 */
113 HWTEST_F(InputMethodServiceTest, test_KeyEvent_CTRL_001, TestSize.Level0)
114 {
115 IMSA_HILOGI("test_KeyEvent_CTRL_001 TEST START");
116 bool result = KeyEventUtil::SimulateKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
117 EXPECT_TRUE(result);
118 usleep(TIME_WAIT_FOR_HANDLE_KEY_EVENT);
119 }
120
121 /**
122 * @tc.name: test_KeyEvent_CTRL_002
123 * @tc.desc: test KeyEvent Callback.
124 * @tc.type: FUNC
125 */
126 HWTEST_F(InputMethodServiceTest, test_KeyEvent_CTRL_002, TestSize.Level0)
127 {
128 IMSA_HILOGI("test_KeyEvent_CTRL_002 TEST START");
129 bool result = KeyEventUtil::SimulateKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_RIGHT);
130 EXPECT_TRUE(result);
131 usleep(TIME_WAIT_FOR_HANDLE_KEY_EVENT);
132 }
133
134 /**
135 * @tc.name: test_KeyEvent_SHIFT_001
136 * @tc.desc: test KeyEvent Callback.
137 * @tc.type: FUNC
138 */
139 HWTEST_F(InputMethodServiceTest, test_KeyEvent_SHIFT_001, TestSize.Level0)
140 {
141 IMSA_HILOGI("test_KeyEvent_SHIFT_001 TEST START");
142 bool result = KeyEventUtil::SimulateKeyEvent(MMI::KeyEvent::KEYCODE_SHIFT_LEFT);
143 EXPECT_TRUE(result);
144 usleep(TIME_WAIT_FOR_HANDLE_KEY_EVENT);
145 }
146
147 /**
148 * @tc.name: test_KeyEvent_SHIFT_002
149 * @tc.desc: test KeyEvent Callback.
150 * @tc.type: FUNC
151 */
152 HWTEST_F(InputMethodServiceTest, test_KeyEvent_SHIFT_002, TestSize.Level0)
153 {
154 IMSA_HILOGI("test_KeyEvent_SHIFT_002 TEST START");
155 bool result = KeyEventUtil::SimulateKeyEvent(MMI::KeyEvent::KEYCODE_SHIFT_RIGHT);
156 EXPECT_TRUE(result);
157 usleep(TIME_WAIT_FOR_HANDLE_KEY_EVENT);
158 }
159
160 /**
161 * @tc.name: test_KeyEvent_CTRL_SHIFT_001
162 * @tc.desc: test KeyEvent Callback.
163 * @tc.type: FUNC
164 */
165 HWTEST_F(InputMethodServiceTest, test_KeyEvent_CTRL_SHIFT_001, TestSize.Level0)
166 {
167 IMSA_HILOGI("test_KeyEvent_CTRL_SHIFT_001 TEST START");
168 bool result =
169 KeyEventUtil::SimulateKeyEvents({ MMI::KeyEvent::KEYCODE_CTRL_LEFT, MMI::KeyEvent::KEYCODE_SHIFT_LEFT });
170 EXPECT_TRUE(result);
171 usleep(TIME_WAIT_FOR_HANDLE_KEY_EVENT);
172 }
173
174 /**
175 * @tc.name: test_KeyEvent_CTRL_SHIFT_002
176 * @tc.desc: test KeyEvent Callback.
177 * @tc.type: FUNC
178 */
179 HWTEST_F(InputMethodServiceTest, test_KeyEvent_CTRL_SHIFT_002, TestSize.Level0)
180 {
181 IMSA_HILOGI("test_KeyEvent_CTRL_SHIFT_002 TEST START");
182 bool result =
183 KeyEventUtil::SimulateKeyEvents({ MMI::KeyEvent::KEYCODE_CTRL_LEFT, MMI::KeyEvent::KEYCODE_SHIFT_RIGHT });
184 EXPECT_TRUE(result);
185 usleep(TIME_WAIT_FOR_HANDLE_KEY_EVENT);
186 }
187
188 /**
189 * @tc.name: test_KeyEvent_CTRL_SHIFT_003
190 * @tc.desc: test KeyEvent Callback.
191 * @tc.type: FUNC
192 */
193 HWTEST_F(InputMethodServiceTest, test_KeyEvent_CTRL_SHIFT_003, TestSize.Level0)
194 {
195 IMSA_HILOGI("test_KeyEvent_CTRL_SHIFT_003 TEST START");
196 bool result =
197 KeyEventUtil::SimulateKeyEvents({ MMI::KeyEvent::KEYCODE_CTRL_RIGHT, MMI::KeyEvent::KEYCODE_SHIFT_LEFT });
198 EXPECT_TRUE(result);
199 usleep(TIME_WAIT_FOR_HANDLE_KEY_EVENT);
200 }
201
202 /**
203 * @tc.name: test_KeyEvent_CTRL_SHIFT_004
204 * @tc.desc: test KeyEvent Callback.
205 * @tc.type: FUNC
206 */
207 HWTEST_F(InputMethodServiceTest, test_KeyEvent_CTRL_SHIFT_004, TestSize.Level0)
208 {
209 IMSA_HILOGI("SubscribeKeyboardEvent007 TEST START");
210 bool result =
211 KeyEventUtil::SimulateKeyEvents({ MMI::KeyEvent::KEYCODE_CTRL_RIGHT, MMI::KeyEvent::KEYCODE_SHIFT_RIGHT });
212 EXPECT_TRUE(result);
213 }
214 } // namespace MiscServices
215 } // namespace OHOS